-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
53 lines (39 loc) · 1.14 KB
/
index.js
File metadata and controls
53 lines (39 loc) · 1.14 KB
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
// Connect to Twitter via API
const express = require('express');
const Twitter = require('twitter');
const Sheet = require('./sheet');
const cron = require('node-cron');
const app = express();
(async () => {
const client = new Twitter({
consumer_key: '',
consumer_secret: '',
access_token_key: '',
access_token_secret: ''
});
// Pull next quote from spreadsheet
const sheet = new Sheet();
await sheet.load();
const quotes = await sheet.getRows();
const status = quotes[0].quote;
// Send the tweet
client.post('statuses/update', { status }, (error, tweet, response) => {
if (error) throw error;
console.log(tweet); // Tweet body.
});
// Remove the quote from spreadsheet
await quotes[0].delete();
console.log('Tweeted', quotes[0].quote);
})();
let testArr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
cron.schedule('* * * * * *', () => {
testArr.pop();
console.log('Popped!', testArr.length);
if (testArr.length === 0) {
// stop();
console.log('Empty');
}
});
app.listen(4000, () => {
console.log(`Server running...`);
});