-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
60 lines (52 loc) · 1.85 KB
/
app.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const config = require('./config')
const twit = require('twit')
const T = new twit(config)
function tweet(myTweet){
T.post('statuses/update', { status: myTweet }, (resp)=> {console.log('tweeted:', resp)});
}
function retweet(searchText) {
// Params to be passed to the 'search/tweets' API endpoint
let params = {
q : searchText + '',
result_type : 'mixed',
count : 1,
}
T.get('search/tweets', params, function(err, data, response){
let tweets = data.statuses
if (!err)
{
let tweetIDList = []
for(let tweet of tweets) {
tweetIDList.push(tweet.id_str);
//to avoid duplication of retweets..
if(tweet.text.startsWith("RT @")){
if(tweet.retweeted_status){
tweetIDList.push(tweet.retweeted_status.id_str);
} else {
tweetIDList.push(tweet.id_str);
}
} else {
tweetIDList.push(tweet.id_str);
}
}
// Call the 'statuses/retweet/:id' API endpoint for retweeting EACH of the tweetID
for (let tweetID of tweetIDList) {
T.post('statuses/retweet/:id', {id : tweetID}, function(err_rt, data_rt, response_rt){
if(!err_rt){
console.log("\n\nRetweeted! ID - " + tweetID)
}
else {
console.log("\nError... Duplication maybe... " + tweetID)
console.log("Error = " + err_rt)
}
})
}
}
else {
console.log("Error while searching" + err_search)
process.exit(1)
}
})
}
tweet('#PeaceForArmenians');
retweet('#RecognizeArtsakh');