-
Notifications
You must be signed in to change notification settings - Fork 0
/
dasher.js
40 lines (33 loc) · 1.02 KB
/
dasher.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
var express = require('express')
, socketio = require('socket.io')
, rss = require('easyrss')
, _ = require('underscore')
, inspect = require('util').inspect;
app = express.createServer();
app.use(express.logger());
app.use(express.static(__dirname + '/public'));
app.listen(80);
//HTTP
app.get('/', function(req, res) {
res.send('sup');
});
//WebSocket
io = socketio.listen(app);
io.sockets.on('connection', function(socket) {
console.log('Client connected');
});
lastChecked = new Date();
lastChecked.setMinutes(lastChecked.getMinutes() - 2);
pollRss = function(){
console.log('Checking RSS...');
rss.parseURL('http://www.reddit.com/new/.rss?sort=new', function(posts) {
_.each(posts.reverse(), function(post){
if (post.pubDate > lastChecked) {
lastChecked = post.pubDate;
io.sockets.emit('newItem', {payload: post.title});
}
});
});
};
setInterval(pollRss, 10000);
console.log('Server started on port %s', app.address().port);