-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
48 lines (38 loc) · 1.14 KB
/
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
39
40
41
42
43
44
45
46
47
48
// Imports
var express = require("express");
var app = require("express")();
var http = require("http").Server(app);
var Twit = require("twit");
var io = require("socket.io")(http);
// Server
http.listen(process.env.PORT || 5000);
app.use(express.static(__dirname + '/public'));
app.get('/', function(req, res){
res.sendfile('index.html');
});
// Twitter
var watchList = [
"#TwitterRealtime"
];
var T = new Twit({
consumer_key: "z4ebhQjySYZcu5aIHUqKgPJiZ",
consumer_secret: "4kVt3glKRLd9dLHIKSi578s4aoZUfmyTwvfonIoXsajOpVWkzF",
access_token: "365489318-9syC9NODIhM5vAalAGTrz9W9THf8ToZ2Jmh6baty",
access_token_secret: "OrGLZBFCgSjPqSdbU1LTsSsbKGfszRGyytEfJ9iVmo3q7"
});
// Socket
io.sockets.on('connection', function(socket) {
var stream = T.stream('statuses/filter', { track: watchList });
stream.on('tweet', function(tweet) {
var tweetJSON = {
text: tweet.text,
name: tweet.user.screen_name,
image: tweet.user.profile_image_url
};
// if tweet has location
if(tweet.place) {
tweetJSON.endereco = tweet.place.full_name + ', ' + tweet.place.country;
}
io.sockets.emit('stream', tweetJSON);
});
});