forked from megancoyle/twitter-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
93 lines (80 loc) · 2.26 KB
/
index.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
require("dotenv").config();
const http = require("http");
const twit = require("twit");
const config = {
consumer_key: process.env.CONSUMER_KEY,
consumer_secret: process.env.CONSUMER_SECRET,
access_token: process.env.ACCESS_TOKEN,
access_token_secret: process.env.ACCESS_TOKEN_SECRET
};
const Twitter = new twit(config);
const MAX_RT_COUNT = 1;
const USERS = [
"15057943", // moma
"14803372", // saam
"5225991", // tate
"22009731", // design museum
"81783051", // artsy
"158865339", // fastcodesign
"20457080", // nga
"24691376", // vangoghmuseum
"17057271", // themet
"16517711", // whitneymuseum
"18201801", // interior design
"19038849", // how design
"2991948728" // thenewpainting
];
const getUserOfTheDay = () => {
let date = new Date();
let dayOfMonth = date.getDate();
let pickUserIndex = dayOfMonth % USERS.length;
return USERS[pickUserIndex];
};
let retweetTags = async function() {
try {
const { data } = await Twitter.get("search/tweets", {
q: "#art, #painting",
result_type: "mixed",
lang: "en"
});
const statuses = data.statuses.slice(0, MAX_RT_COUNT);
// loop through the first n returned tweets
for (const status of statuses) {
// the post action
const response = await Twitter.post("statuses/retweet/:id", {
id: status.id_str
});
if (response) {
console.log("Successfully retweeted");
}
}
} catch (err) {
// catch all log if the search/retweet could not be executed
console.error("Err:", err);
}
};
// retweetTags();
let retweetUsers = async function() {
try {
const { data } = await Twitter.get("users/show", {
user_id: getUserOfTheDay()
});
const status = data.status;
// make sure tweet isn't in reply to another user
if (status.in_reply_to_status_id == null) {
const response = await Twitter.post("statuses/retweet/:id", {
id: status.id_str
});
if (response) {
console.log("Successfully retweeted");
}
}
} catch (err) {
// catch all log if the search/retweet could not be executed
console.error("Err:", err);
}
};
retweetUsers();
setInterval(function() {
http.get("https://twitterbot-retweet.herokuapp.com/");
}, 86400000); // checks app every 24 hours