mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Let feedparser ignore initial "old" stories
This commit is contained in:
parent
aabba8fe89
commit
63012a7ae3
@ -7,6 +7,11 @@
|
|||||||
<label for="node-input-interval"><i class="fa fa-repeat"></i> <span data-i18n="feedparse.label.refresh"></span></label>
|
<label for="node-input-interval"><i class="fa fa-repeat"></i> <span data-i18n="feedparse.label.refresh"></span></label>
|
||||||
<input type="text" id="node-input-interval" style="width:60px"> <span data-i18n="feedparse.label.minutes"></span>
|
<input type="text" id="node-input-interval" style="width:60px"> <span data-i18n="feedparse.label.minutes"></span>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label> </label>
|
||||||
|
<input type="checkbox" id="node-input-ignorefirst" style="display:inline-block; width:20px; vertical-align:baseline;">
|
||||||
|
<span data-i18n="feedparse.label.ignorefirst"></span>
|
||||||
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="node-red:common.label.name"></span></label>
|
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="node-red:common.label.name"></span></label>
|
||||||
<input type="text" id="node-input-name" data-i18n="[placeholder]node-red:common.label.name">
|
<input type="text" id="node-input-name" data-i18n="[placeholder]node-red:common.label.name">
|
||||||
@ -20,7 +25,8 @@
|
|||||||
defaults: {
|
defaults: {
|
||||||
name: {value:""},
|
name: {value:""},
|
||||||
url: {value:"", required:true},
|
url: {value:"", required:true},
|
||||||
interval: { value:15, required:true, validate:function(v) {return (!isNaN(parseInt(v)) && (parseInt(v) <= 35790))} }
|
interval: { value:15, required:true, validate:function(v) {return (!isNaN(parseInt(v)) && (parseInt(v) <= 35790))} },
|
||||||
|
ignorefirst: { value:false }
|
||||||
},
|
},
|
||||||
inputs:0,
|
inputs:0,
|
||||||
outputs:1,
|
outputs:1,
|
||||||
|
@ -11,11 +11,13 @@ module.exports = function(RED) {
|
|||||||
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;
|
||||||
this.interval_id = null;
|
this.interval_id = null;
|
||||||
|
this.ignorefirst = n.ignorefirst || false;
|
||||||
this.seen = {};
|
this.seen = {};
|
||||||
|
this.donefirst = false;
|
||||||
var node = this;
|
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) {
|
||||||
node.error(RED._("feedparse.errors.invalidurl"));
|
node.error(RED._("feedparse.errors.invalidurl"),RED._("feedparse.errors.invalidurl"));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var getFeed = function() {
|
var getFeed = function() {
|
||||||
@ -33,27 +35,32 @@ module.exports = function(RED) {
|
|||||||
else { res.pipe(feedparser); }
|
else { res.pipe(feedparser); }
|
||||||
});
|
});
|
||||||
|
|
||||||
feedparser.on('error', function(error) { node.error(error); });
|
feedparser.on('error', function(error) { node.error(error,error); });
|
||||||
|
|
||||||
feedparser.on('readable', function () {
|
feedparser.on('readable', function () {
|
||||||
var stream = this, article;
|
var stream = this, article;
|
||||||
while (article = stream.read()) { // jshint ignore:line
|
while (article = stream.read()) { // jshint ignore:line
|
||||||
if (!(article.guid in node.seen) || ( node.seen[article.guid] !== 0 && node.seen[article.guid] != article.date.getTime())) {
|
if (!(article.guid in node.seen) || ( node.seen[article.guid] !== 0 && node.seen[article.guid] != article.date.getTime())) {
|
||||||
node.seen[article.guid] = article.date?article.date.getTime():0;
|
node.seen[article.guid] = article.date ? article.date.getTime() : 0;
|
||||||
var msg = {
|
var msg = {
|
||||||
topic: article.origlink || article.link,
|
topic: article.origlink || article.link,
|
||||||
payload: article.description,
|
payload: article.description,
|
||||||
article: article
|
article: article
|
||||||
};
|
};
|
||||||
|
if (node.ignorefirst === true && node.donefirst === false) {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
else {
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
feedparser.on('meta', function (meta) {});
|
feedparser.on('meta', function (meta) {});
|
||||||
feedparser.on('end', function () {});
|
feedparser.on('end', function () {});
|
||||||
};
|
};
|
||||||
node.interval_id = setInterval(function() { getFeed(); }, node.interval);
|
node.interval_id = setInterval(function() { node.donefirst = true; getFeed(); }, node.interval);
|
||||||
getFeed();
|
getFeed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,8 @@
|
|||||||
"label": {
|
"label": {
|
||||||
"feedurl": "Feed url",
|
"feedurl": "Feed url",
|
||||||
"refresh": "Refresh",
|
"refresh": "Refresh",
|
||||||
"minutes": "minutes"
|
"minutes": "minutes",
|
||||||
|
"ignorefirst": "Ignore any stories older than restart"
|
||||||
},
|
},
|
||||||
"errors": {
|
"errors": {
|
||||||
"badstatuscode": "error - Bad status code",
|
"badstatuscode": "error - Bad status code",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "node-red-node-feedparser",
|
"name": "node-red-node-feedparser",
|
||||||
"version": "0.2.2",
|
"version": "0.3.0",
|
||||||
"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",
|
||||||
@ -15,7 +15,8 @@
|
|||||||
"keywords": [
|
"keywords": [
|
||||||
"node-red",
|
"node-red",
|
||||||
"atom",
|
"atom",
|
||||||
"rss"
|
"rss",
|
||||||
|
"feed"
|
||||||
],
|
],
|
||||||
"node-red": {
|
"node-red": {
|
||||||
"nodes": {
|
"nodes": {
|
||||||
|
Loading…
Reference in New Issue
Block a user