-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfollow-retweeter.js
58 lines (48 loc) · 1.11 KB
/
follow-retweeter.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
50
51
52
53
54
55
56
57
58
var util = require('util');
var twitter = require('twitter');
var twit = new twitter({
consumer_key: '',
consumer_secret: '',
access_token_key: '',
access_token_secret: ''
});
var hashtag = '#15below'
var hashtagRegex = new RegExp(hashtag, "i");
function write(data) {
if ( typeof data === 'string') {
console.log(data);
}
else if (data.text && data.user && data.user.screen_name) {
console.log(data.user.screen_name + ": " + data.text);
testForHashtag(data);
}
else if (data.delete) {
console.log('DELETE');
}
else if (data.message) {
console.log('ERROR' + data.message);
}
else {
console.log(util.inspect(data));
}
}
function testForHashtag(data) {
if(data.retweeted) return;
if(data.text.match(hashtagRegex) !== null) {
twit.retweetStatus(data.id_str, function(){
console.log('retweet callback');
});
}
}
function reconnect() {
setTimeout(startStreaming, 1000);
}
function startStreaming() {
twit.stream('user', function(stream) {
console.log('starting stream');
stream.on('data', write);
stream.on('end', reconnect)
});
}
startStreaming();
console.log('lisening for tweets');