-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
47 lines (42 loc) · 1.06 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
const Twit = require("twit");
const dotenv = require("dotenv");
const request = require("request");
dotenv.config();
const T = new Twit({
consumer_key: process.env.TWITTER_CONSUMER_KEY,
consumer_secret: process.env.TWITTER_CONSUMER_SECRET,
access_token: process.env.ACCESS_TOKEN,
access_token_secret: process.env.ACCESS_TOKEN_SECRET,
});
function tweeted(error, data, response) {
if (error) {
console.log(error.twitterReply);
console.log("something went wrong");
} else {
console.log("Tweet sent");
}
}
function postQuotes() {
request(
"https://zenquotes.io/api/random",
{ json: true },
function (err, res, [body]) {
if (err) {
return console.log(err);
}
function tweetIt() {
const tweet = {
status: body.q + " - " + `${body.a || "Unknown"}`,
};
if (body) {
T.post("statuses/update", tweet, tweeted);
} else {
console.log("no quote found");
}
}
return tweetIt();
}
);
}
postQuotes();
setInterval(postQuotes, 1000 * 60 * 60);