-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
executable file
·55 lines (48 loc) · 1.42 KB
/
server.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
var express = require('express'),
faye = require('faye'),
TwitterNode = require('twitter-node').TwitterNode,
sys = require('sys'),
util = require('util'),
twitCount = 0,
twit = new TwitterNode({
user:"",
password:"",
locations:[ -168, -60, 168, 83 ]
}),
bayeux = new faye.NodeAdapter({
mount:'/faye',
timeout:45
}),
app = express.createServer();
// configure express
app.configure(function () {
app.use(express.bodyParser());
app.use(express.static(__dirname + '/public'));
});
bayeux.attach(app);
app.listen(1337);
// configure twitter client
twit.addListener('error', function (error) {
console.log(error.message);
});
twit.addListener('tweet',function (tweet) {
if (!!tweet.geo) {
// limit the amount of tweets we take
if (twitCount++ % 15 === 0) {
sys.puts("@" + tweet.user.screen_name + ": " + tweet.text);
sys.puts("geo --> " + util.inspect(tweet.geo, true, null));
bayeux.getClient().publish('/channel', {
"city":tweet.user.screen_name,
"lat":tweet.geo.coordinates[0],
"long":tweet.geo.coordinates[1]
});
}
}
}).addListener('limit',function (limit) {
sys.puts("LIMIT: " + sys.inspect(limit));
}).addListener('delete',function (del) {
sys.puts("DELETE: " + sys.inspect(del));
}).addListener('end', function (resp) {
sys.puts("END: " + sys.inspect(resp));
});
twit.stream();