-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
41 lines (37 loc) · 1.02 KB
/
index.js
File metadata and controls
41 lines (37 loc) · 1.02 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
const getTweets = require('./utils/getTweets');
const keywords = require('./keywords.json');
const fs = require('fs');
async function sleep(milliseconds) {
return new Promise(resolve => {
setTimeout(() => {
resolve();
}, milliseconds);
});
}
async function addToCsv(tweets) {
return new Promise(async (resolve, reject) => {
try {
let text = tweets.map(tweet => {
return `${tweet.replaceAll('\n', " ")}\n`;
});
await fs.appendFileSync('../data/tweets.txt', text.join(''));
resolve();
} catch (err) {
reject(err);
}
});
}
async function startScraping() {
while (true) {
for(let index in keywords.candidatos) {
try {
const tweets = await getTweets(keywords.candidatos[index]);
await addToCsv(tweets);
} catch (err) {
console.error(err);
}
}
await sleep(300000);
}
}
startScraping();