mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
parent
1bb31ba7ad
commit
4ee6e57111
@ -10,19 +10,19 @@ module.exports = function(RED) {
|
|||||||
this.url = n.url;
|
this.url = n.url;
|
||||||
if (n.interval > 35790) { this.warn(RED._("feedparse.errors.invalidinterval")) }
|
if (n.interval > 35790) { this.warn(RED._("feedparse.errors.invalidinterval")) }
|
||||||
this.interval = (parseInt(n.interval)||15) * 60000;
|
this.interval = (parseInt(n.interval)||15) * 60000;
|
||||||
var node = this;
|
|
||||||
this.interval_id = null;
|
this.interval_id = null;
|
||||||
this.seen = {};
|
this.seen = {};
|
||||||
|
var node = this;
|
||||||
var parsedUrl = url.parse(this.url);
|
var parsedUrl = url.parse(this.url);
|
||||||
if (!(parsedUrl.host || (parsedUrl.hostname && parsedUrl.port)) && !parsedUrl.isUnix) {
|
if (!(parsedUrl.host || (parsedUrl.hostname && parsedUrl.port)) && !parsedUrl.isUnix) {
|
||||||
this.error(RED._("feedparse.errors.invalidurl"));
|
node.error(RED._("feedparse.errors.invalidurl"));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var getFeed = function() {
|
var getFeed = function() {
|
||||||
var req = request(node.url, {timeout:10000, pool:false});
|
var req = request(node.url, {timeout:10000, pool:false});
|
||||||
//req.setMaxListeners(50);
|
//req.setMaxListeners(50);
|
||||||
req.setHeader('user-agent', 'Mozilla/5.0 (Node-RED)');
|
req.setHeader('user-agent', 'Mozilla/5.0 (Node-RED)');
|
||||||
req.setHeader('accept', 'application/rss+xml,text/html,application/xhtml+xml');
|
req.setHeader('accept', 'application/rss+xml,text/html,application/xhtml+xml,application/xml');
|
||||||
|
|
||||||
var feedparser = new FeedParser();
|
var feedparser = new FeedParser();
|
||||||
|
|
||||||
@ -53,11 +53,11 @@ module.exports = function(RED) {
|
|||||||
feedparser.on('meta', function (meta) {});
|
feedparser.on('meta', function (meta) {});
|
||||||
feedparser.on('end', function () {});
|
feedparser.on('end', function () {});
|
||||||
};
|
};
|
||||||
this.interval_id = setInterval(function() { getFeed(); }, node.interval);
|
node.interval_id = setInterval(function() { getFeed(); }, node.interval);
|
||||||
getFeed();
|
getFeed();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.on("close", function() {
|
node.on("close", function() {
|
||||||
if (this.interval_id != null) {
|
if (this.interval_id != null) {
|
||||||
clearInterval(this.interval_id);
|
clearInterval(this.interval_id);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "node-red-node-feedparser",
|
"name": "node-red-node-feedparser",
|
||||||
"version": "0.2.1",
|
"version": "0.2.2",
|
||||||
"description": "A Node-RED node to get RSS Atom feeds.",
|
"description": "A Node-RED node to get RSS Atom feeds.",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"feedparser": "^2.2.10",
|
"feedparser": "^2.2.10",
|
||||||
|
Loading…
Reference in New Issue
Block a user