forked from sjwhitmore/tweet-collector
-
Notifications
You must be signed in to change notification settings - Fork 10
/
getTweets.js
33 lines (27 loc) · 956 Bytes
/
getTweets.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
var twitter = require('twitter')
, fs = require('fs')
, mongojs = require('mongojs')
// Config
var connectionString = process.env.MONGO_URL ? process.env.MONGO_URL +'/tweets' : 'tweets'
, collectionName = 'talkpay'
, hashtag = '#talkpay'
var db = mongojs.connect(connectionString, [collectionName])
// If undefined in our process load our local file
// (i.e. we aren't on an external server where we set these differently)
if(!process.env.CONSUMER_KEY) {
var env = require('./env.js')
}
var client = new twitter({
consumer_key: process.env.CONSUMER_KEY,
consumer_secret: process.env.CONSUMER_SECRET,
access_token_key: process.env.ACCESS_TOKEN_KEY,
access_token_secret: process.env.ACCESS_TOKEN_SECRET
})
client.stream('statuses/filter', {track: hashtag}, function(stream) {
stream.on('data', function(tweet) {
db.talkpay.insert(tweet)
})
stream.on('error', function(err) {
console.log(err)
})
})