-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
94 lines (79 loc) · 2.25 KB
/
app.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Serveur.js
var server = require('http').createServer(handler);
var fs = require('fs');
var consumer_key = 'xx';
var consumer_secret = 'xx';
var access_token_key = 'xx-xx';
var access_token_secret = 'xx';
var io = require('socket.io').listen(server);
io.set('log level', 1);
//console.log('Socket open');
var twitter = require('ntwitter');
var twit = new twitter({
consumer_key: consumer_key,
consumer_secret: consumer_secret,
access_token_key: access_token_key,
access_token_secret: access_token_secret
});
function handler (req, res) {
fs.readFile(__dirname + '/public/index.html', 'utf-8', function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading index.html');
}
res.writeHead(200);
res.write(data);
res.end();
});
// tweet history res.end();
setTimeout( function() {
twit.search('phptour OR afup OR phptournantes', {}, function(err, datas) {
tab = datas.results;
tab.reverse();
//sleep(10000);
tab.forEach(function (data) {
if (data.text)
{
// check tweet !
if (!data.retweeted)
{
io.sockets.emit('tweet', {
text: data.text,
user_name: data.from_user_name,
user_image: data.profile_image_url_https
});
//console.log(data.text);
}
}
});
});
}, 2000);
}
server.listen(8080);
console.log('Server running at http://127.0.0.1:8080/');
twit.stream('statuses/filter', {track: ['phptour', 'afup', 'phptournantes'] }, function(stream) {
stream.on('data', function (data) {
// var tweet_content = Array();
if (data.text)
{
// check tweet !
if (!data.retweeted)
{
io.sockets.emit('tweet', {
text: data.text,
user_name: data.user.screen_name,
user_image: data.user.profile_image_url_https
});
}
}
});
stream.on('end', function (response) {
console.log('end ????');
// Handle a disconnection
});
stream.on('destroy', function (response) {
// Handle a 'silent' disconnection from Twitter, no end/error event fired
});
// Disconnect stream after five seconds
//setTimeout(stream.destroy, 5000);
});