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
Showing
1 changed file
with
32 additions
and
30 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 |
---|---|---|
@@ -1,41 +1,43 @@ | ||
// Our Twitter library | ||
var Twit = require('twit'); | ||
const Twit = require("twit"); | ||
|
||
// We need to include our configuration file | ||
var T = new Twit(require('./config.js')); | ||
const twit = new Twit(require("./config.js")); | ||
|
||
// This is the URL of a search for the latest tweets on the '#MeetMaye' hashtag. | ||
var mediaArtsSearch = {q: "#MeetMaye", count: 100, result_type: "recent"}; | ||
const mediaArtsSearch = { q: "#MeetMaye", count: 100, 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); | ||
} | ||
}); | ||
// This function finds the latest tweet with the MeetMaye hashtag and retweets. | ||
const retweetLatest = () => { | ||
twit.get("search/tweets", mediaArtsSearch, (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 retweetwit... | ||
let retweetId = data.statuses[0].id_str; | ||
// ...and then we tell Twitter we want to retweet it! | ||
twit.post("statuses/retweet/" + retweetId, {}, (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/half after that. Time here is in milliseconds, so | ||
// ...and then every hour/half thereafter. 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 * 30); | ||
setInterval(retweetLatest, 1000 * 60 * 30); |