-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
117 lines (89 loc) · 2.55 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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
var express = require('express')
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var routes = require('./routes/index');
var users = require('./routes/users');
var Twit = require('twit');
var app = express();
var http = require('http');
var swig = require('swig');
var app = new express();
var server = http.createServer(app);
var io = require('socket.io').listen(server);
server.listen(8080);
console.log("Listening on port 8080");
// view engine setup
app.engine('html', swig.renderFile);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'html');
// uncomment after placing your favicon in /public
//app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
//Twitter details
var T = new Twit({
consumer_key: ''
, consumer_secret: ''
, access_token: ''
, access_token_secret: ''
});
// routing
var twitterWatchList = [];
app.get('/tweets/:tword',function(req,res)
{
var trackword = req.param('tword');
twitterWatchList.push(trackword);
res.redirect('/getTweets');
});
app.get('/getTweets', function (req, res) {
res.render('liveTweets.html');
io.sockets.on('connection', function (socket) {
//console.log(socket.connection);
console.log('Connected');
});
var stream = T.stream('statuses/filter', { track: twitterWatchList, language: 'en' })
stream.on('tweet', function (tweet) {
io.sockets.emit('stream',tweet);
});
});
var twitterCelebList = [];
var options = {};
app.get('/celebTweets/:celebSceenName',function(req,res)
{
var screenName = req.param('celebSceenName');
twitterCelebList.push(screenName);
options = { screen_name: twitterCelebList ,count: 20 };
res.redirect('/getCelebTweets');
});
app.get('/getCelebTweets',function(req,res)
{
T.get('statuses/user_timeline', options , function(err, data) {
res.render('celebTweets',{ tweets:data });
});
});
app.get('/',function(req,res)
{
res.render('homePage-sports');
});
app.get('/entertainment',function(req,res)
{
res.render('homePage-entertainment');
});
app.get('/world',function(req,res)
{
res.render('homePage-world');
});
app.get('/technology',function(req,res)
{
res.render('homePage-technology');
});
app.get('/celebs',function(req,res)
{
res.render('homePage-celebrities');
});