-
Notifications
You must be signed in to change notification settings - Fork 1
/
gather.js
31 lines (26 loc) · 1006 Bytes
/
gather.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
const Twit = require('twit');
const { writeFile } = require('fs-extra');
const { join } = require('path');
const { hashtags, dataPath } = require('./local-constants');
const consumer_key = process.env['CONSUMER_KEY'];
const consumer_secret = process.env['CONSUMER_SECRET'];
const access_token = process.env['ACCESS_TOKEN'];
const access_token_secret = process.env['ACCESS_TOKEN_SECRET'];
const T = new Twit({
consumer_key: consumer_key,
consumer_secret: consumer_secret,
access_token: access_token,
access_token_secret: access_token_secret,
});
async function searchTweets(query) {
var {data} = await T.get('search/tweets', { q: query, count: 100 });
return data['statuses'];
}
function gatherData(...hashtags) {
hashtags.forEach(async function(hashtag) {
var data = await searchTweets(hashtag);
console.log(`Found ${data.length} for ${hashtag}`);
await writeFile(join(dataPath, `${hashtag}.json`), JSON.stringify(data));
});
}
gatherData(...hashtags)