This repository was archived by the owner on May 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrss.js
61 lines (57 loc) · 1.8 KB
/
rss.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
/*global Buffer: false, clearInterval: false, clearTimeout: false, console: false, global: false, exports:false, module: false, process: false, querystring: false, require: false, setInterval: false, setTimeout: false, __filename: false, __dirname: false */
/*
* RSS Feed Reader Module
* Copyright 2011 Jaakko-Heikki Heusala <[email protected]>
*/
var rssee = require('rssee'),
util = require('util');
function RSSReaderModule(settings) {
var mod = this,
queue = [],
f,
feed_opts,
rss;
mod.settings = settings || {};
mod.routes = [];
mod.interval = null;
if(!mod.settings.interval) {
mod.settings.interval = 15*1000;
}
mod.feeds = {};
function queue_push(a) {
if(settings.debug) {
util.log('[rss] Received new article, adding it to the queue.');
}
queue.push(a);
}
for(f in mod.settings.feeds) {
if(mod.settings.feeds.hasOwnProperty(f)) {
feed_opts = mod.settings.feeds[f];
if(!feed_opts.interval) {
feed_opts.interval = mod.settings.interval;
}
rss = rssee.create({'interval': feed_opts.interval/1000 });
mod.feeds[f] = rss;
rss.on('article', queue_push);
if(settings.debug) {
util.log('[rss] Watching now ' + f + ' with url="' + feed_opts.url + '", interval=' + feed_opts.interval + '.');
}
rss.start(feed_opts.url);
}
}
mod.intervals = [[ function(cb) {
if(settings.debug) {
util.log('[rss] Queue has ' + queue.length + ' items.'+ ((queue.length!==0) ? ' Loading it now.' : '') );
}
var a, title, link;
do {
a = queue.shift();
if(a) {
title = a.title || 'Untitled';
link = a.link || '[no link]';
cb('[rss] ' + title + ' - ' + link);
}
} while(a);
}, mod.settings.interval]];
}
exports.Module = RSSReaderModule;