-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (38 loc) · 1.69 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
const fs = require('fs');
const Twit = require('twit');
const metrics = require('datadog-metrics');
let raw = fs.readFileSync('./config.json');
let config = JSON.parse(raw);
metrics.init({ host: 'onetap', prefix: 'onetap_v2.', appKey: config['appKey'], apiKey: config['apiKey'] });
let T = new Twit({
consumer_key: config['CONSUMER_KEY'],
consumer_secret: config['CONSUMER_SECRET'],
access_token: config['ACCESS_TOKEN'],
access_token_secret: config['ACCESS_TOKEN_SECRET']
});
let teamJokowi = 0;
let teamPrabowo = 0;
let pemilu = 0;
let jkwStream = T.stream('statuses/filter', { track: ['#JokoWinElection', 'jokowi', 'maaruf', '01']} );
jkwStream.on('tweet', (tweet) => {
teamJokowi = teamJokowi + 1
console.log(`${new Date()}: JKW ${tweet.user.screen_name}(${tweet.user.id}) ${tweet.text} (${tweet.retweet_count}/${tweet.favorite_count})`)
})
let prbStream = T.stream('statuses/filter', { track: ['#TheVictoryOfPrabowo', 'prabowo', 'sandiaga', '02']} );
prbStream.on('tweet', (tweet) => {
teamPrabowo = teamPrabowo + 1
console.log(`${new Date()}: PRB ${tweet.user.screen_name}(${tweet.user.id}) ${tweet.text} (${tweet.retweet_count}/${tweet.favorite_count})`)
})
let pemiluStream = T.stream('statuses/filter', { track: '#Pemilu2019'} );
pemiluStream.on('tweet', (tweet) => {
pemilu = pemilu + 1
console.log(`${new Date()}: PEMILU ${tweet.user.screen_name}(${tweet.user.id}) ${tweet.text} (${tweet.retweet_count}/${tweet.favorite_count})`)
})
setInterval(() => {
metrics.gauge(`stream.teamJkw`, teamJokowi);
metrics.gauge(`stream.teamPrb`, teamPrabowo);
metrics.gauge(`stream.pemilu`, pemilu);
pemilu = 0;
teamJokowi = 0;
teamPrabowo = 0;
}, 120000) //every 5 minutes report to datadog