forked from PATRIC3/p3_web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnews.js
54 lines (40 loc) · 1.09 KB
/
news.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
var request = require('request');
var FeedParser = require('feedparser');
var conf = require("./config");
var Query = require("rql/js-array").query;
var News = []
function GetNews() {
console.log("Refreshing News from RSS Feed");
var news = [];
var req = request(conf.get("newsFeedRSS"));
feedparser = new FeedParser([]);
req.on('error', function (error) {
// handle any request errors
});
req.on('response', function (res) {
var stream = this;
if (res.statusCode != 200) return this.emit('error', new Error('Bad status code'));
stream.pipe(feedparser);
});
feedparser.on('error', function(error) {
// always handle errors
});
feedparser.on('readable', function() {
// This is where the action is!
var stream = this
, meta = this.meta // **NOTE** the "meta" is always available in the context of the feedparser instance
, item;
while (item = stream.read()) {
news.push(item);
}
});
News=news;
}
GetNews();
setInterval(function(){
GetNews();
},60 * 1000 *60);
module.exports = function(query){
console.log("query: ", query);
return Query(query,{},News);
}