forked from mayeedwin/twitterbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
retweetbot.js
41 lines (37 loc) · 1.52 KB
/
retweetbot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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 '#MeetMaye' hashtag.
var mediaArtsSearch = {q: "#MeetMaye", count: 10, result_type: "recent"};
// This function finds the latest tweet with the #MeetMaye 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! Retweet Successful!')
}
// 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
// 1000 ms = 1 second, 1 sec * 60 = 1 min, 1 min * 60 = 1 hour --> 1000 * 60 * 60
setInterval(retweetLatest, 1000 * 60 * 60);