-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
38 lines (29 loc) · 925 Bytes
/
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
var candyMachine = require("./hardware");
var app = require("./server");
app.candyMachine = candyMachine;
// Twitter stuff.
require("./configure")(app);
app.configure();
var startTwitterListener = function(){
var stream = app.T.stream('statuses/filter', { track: 'RaspberryPi' });
stream.on('tweet', function (tweet) {
if(!tweet.retweeted_status){
console.log(tweet.user.name + ': ' + tweet.text);
console.log(' ');
if(app.candyMachine){
app.candyMachine.dispense();
}
} else{
console.warn('RT doesn\'t count '+ tweet.user.name);
}
});
stream.on('limit', function (limitMessage) {
console.error('You\'re hitting the twitter limit.');
});
// on error try again 5 seconds later
stream.on('error', function(){
setTimeout( startTwitterListener , 5000);
});
}
// first attempt after 2 seconds.:
setTimeout( startTwitterListener , 2000);