forked from mayeedwin/twitterbot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 610faa2
Showing
6 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Build and Release Folders | ||
bin-debug/ | ||
bin-release/ | ||
[Oo]bj/ | ||
[Bb]in/ | ||
|
||
# Other files and folders | ||
.settings/ | ||
|
||
# Executables | ||
*.swf | ||
*.air | ||
*.ipa | ||
*.apk | ||
|
||
# Project files, i.e. `.project`, `.actionScriptProperties` and `.flexProperties` | ||
# should NOT be excluded as they contain compiler settings and other important | ||
# information for Eclipse / Flash Builder. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 Maye Edwin | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# ExampleBot | ||
|
||
This bot retweets the latest tweet using the "#mediaarts" hashtag. It attempts to retweet once per hour. | ||
|
||
_Note: you must be comfortable using your computer's command line interface to use this bot. If you've never used it, there are tutorials for [Mac OSX](http://blog.teamtreehouse.com/introduction-to-the-mac-os-x-command-line) and [Windows](http://www.bleepingcomputer.com/tutorials/windows-command-prompt-introduction/)._ | ||
|
||
## Installation | ||
|
||
If you don't already have have them, please install [Node.js](http://nodejs.org/). This will install two programs: `node`, which runs JavaScript from the command line, and `npm`, which helps you install software that Node.js can run. | ||
|
||
Make an empty project directory somewhere convenient for you, [download this file](https://github.com/dariusk/examplebot/archive/master.zip), and unzip the contents to your project directory. Go to your project directory in the command line. There should be four files there: `.gitignore`, `README.md`, `bot.js` and `config.js`. In that directory type: | ||
|
||
`npm install twit` | ||
|
||
This installs some code to the `npm_modules` subdirectory, which you don't need to worry about. (It's Twit, the library that lets us talk to Twitter.) | ||
|
||
## Connecting to Twitter | ||
|
||
At this point you need to register a Twitter account and also get its "app info". | ||
|
||
So create a Twitter account for whatever account you want to tweet this stuff. Twitter doesn't allow you to register multiple twitter accounts on the same email address. I recommend you create a brand new email address (perhaps using Gmail) for the Twitter account. Once you register the account to that email address, wait for the confirmation email. Then go here and log in as the Twitter account for your bot: | ||
|
||
https://apps.twitter.com/app/new | ||
|
||
Once you're there, fill in the required fields: name, description, website. None of it really matters at all to your actual app, it's just for Twitter's information. Do the captcha and submit. | ||
|
||
Next you'll see a screen with a "Details" tab. Click on the "Settings" tab and under "Application Type" choose "Read and Write", then hit the update button at the bottom. | ||
|
||
Then go to the Keys and Access Tokens tab, and at the bottom click "create my access token". Nothing might happen immediately. Wait a minute and reload the page. then there should be "access token" and "access token secret", which are both long strings of letters and numbers. | ||
|
||
Now use a text editor to open up the "config.js" file. It should look like this: | ||
|
||
```javascript | ||
module.exports = { | ||
consumer_key: 'blah', | ||
consumer_secret: 'blah', | ||
access_token: 'blah', | ||
access_token_secret: 'blah' | ||
} | ||
``` | ||
|
||
In between those quotes, instead of `'blah'`, paste the appropriate info from the Details page. This is essentially the login information for the app. | ||
|
||
Now type the following in the command line in your project directory: | ||
|
||
`node bot.js` | ||
|
||
Hopefully at this point you see a message like "Success! Check your bot, it should have retweeted something." Check the Twitter account for your bot, and it should have retweeted a tweet with the #mediaarts hashtag. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Put your own Twitter App keys here. See README.md for more detail. | ||
module.exports = { | ||
consumer_key: 'blah', | ||
consumer_secret: 'blah', | ||
access_token: 'blah', | ||
access_token_secret: 'blah' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Our Twitter library | ||
var Twit = require('twit'); | ||
|
||
// We need to include our configuration file | ||
var T = new Twit(require('./config.js')); | ||
|
||
// This is the URL of a search for the latest tweets on the '#mediaarts' hashtag. | ||
var mediaArtsSearch = {q: "#mediaarts", count: 10, result_type: "recent"}; | ||
|
||
// This function finds the latest tweet with the #mediaarts hashtag, and retweets it. | ||
function retweetLatest() { | ||
T.get('search/tweets', mediaArtsSearch, function (error, data) { | ||
// log out any errors and responses | ||
console.log(error, data); | ||
// If our search request to the server had no errors... | ||
if (!error) { | ||
// ...then we grab the ID of the tweet we want to retweet... | ||
var retweetId = data.statuses[0].id_str; | ||
// ...and then we tell Twitter we want to retweet it! | ||
T.post('statuses/retweet/' + retweetId, { }, function (error, response) { | ||
if (response) { | ||
console.log('Success! Check your bot, it should have retweeted something.') | ||
} | ||
// If there was an error with our Twitter call, we print it out here. | ||
if (error) { | ||
console.log('There was an error with Twitter:', error); | ||
} | ||
}) | ||
} | ||
// However, if our original search request had an error, we want to print it out here. | ||
else { | ||
console.log('There was an error with your hashtag search:', error); | ||
} | ||
}); | ||
} | ||
|
||
// Try to retweet something as soon as we run the program... | ||
retweetLatest(); | ||
// ...and then every hour after that. Time here is in milliseconds, so | ||
// 1000 ms = 1 second, 1 sec * 60 = 1 min, 1 min * 60 = 1 hour --> 1000 * 60 * 60 | ||
setInterval(retweetLatest, 1000 * 60 * 60); |