-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
74 lines (63 loc) · 1.68 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
'use strict'
/**
* Module dependencies.
*/
var app = require('express.io')()
, util = require('util')
, express = require('express')
, routes = require('./routes')
, user = require('./routes/user')
, http = require('http')
, path = require('path')
, twitter = require('ntwitter')
, EventEmitter = require('events').EventEmitter
, emitter = new EventEmitter()
, minutes = 0
, dbReady = false
, fs = require('fs');
var port = process.env.PORT || 5000;
app.http().io();
// all environments
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
// development only
if ('development' == app.get('env')) {
app.use(express.errorHandler());
}
app.get('/', routes.index);
var twit = new twitter({
consumer_key: 'AH AH AH',
consumer_secret: 'YOU DIDNT SAY THE MAGIC WORD',
access_token_key: 'HEE HEE',
access_token_secret: 'CINNAMON BUNS'
});
function startStream() {
twit.stream('statuses/filter', {locations: '-124.848974,24.396308,-66.885444,49.384358' }, function(stream) {
stream.on('data',function(data) {
try {
var dataObj = {
coords: data.coordinates.coordinates,
};
app.io.broadcast('tweet',dataObj);
} catch(e) {
}
});
stream.on('end', function(response) {
console.error('STREAM CLOSED: ' , response)
startStream()
});
stream.on('destroy', function(response) {
console.log('STREAM DESTROYED: ', response)
})
});
}
app.listen(port, function() {
console.log("Listening on " + port);
});
startStream();