-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwitter.js
More file actions
40 lines (36 loc) · 773 Bytes
/
twitter.js
File metadata and controls
40 lines (36 loc) · 773 Bytes
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
var http = require('http')
, bot
, options = {
host : 'search.twitter.com'
, path : '/search.json?q=OpenVE&rpp=5&result_type=recent'
, method : 'GET'
}
, time = 1000 * 30 // 30 Seconds
exports.init = function(_bot) {
bot = _bot
makeRequests()
}
function makeRequests() {
var req = http.request(options, gotResults)
req.end()
req.on('error', gotError)
}
function gotResults(res) {
var data = ''
res.on('data', function(chunk) {
data += chunk
})
res.on('end', function() {
try {
data = JSON.parse(data)
} catch(e) {
return gotError(e)
}
bot.controller.twitterSearch(data)
setTimeout(makeRequests, time)
})
}
function gotError(error) {
console.log(error)
setTimeout(makeRequests, time)
}