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>
|
||||
<input type="text" id="node-input-interval" style="width:60px"> <span data-i18n="feedparse.label.minutes"></span>
|
||||
</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">
|
||||
<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">
|
||||
@ -20,7 +25,8 @@
|
||||
defaults: {
|
||||
name: {value:""},
|
||||
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,
|
||||
outputs:1,
|
||||
|
@ -11,11 +11,13 @@ module.exports = function(RED) {
|
||||
if (n.interval > 35790) { this.warn(RED._("feedparse.errors.invalidinterval")) }
|
||||
this.interval = (parseInt(n.interval)||15) * 60000;
|
||||
this.interval_id = null;
|
||||
this.ignorefirst = n.ignorefirst || false;
|
||||
this.seen = {};
|
||||
this.donefirst = false;
|
||||
var node = this;
|
||||
var parsedUrl = url.parse(this.url);
|
||||
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 {
|
||||
var getFeed = function() {
|
||||
@ -33,27 +35,32 @@ module.exports = function(RED) {
|
||||
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 () {
|
||||
var stream = this, article;
|
||||
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())) {
|
||||
node.seen[article.guid] = article.date?article.date.getTime():0;
|
||||
node.seen[article.guid] = article.date ? article.date.getTime() : 0;
|
||||
var msg = {
|
||||
topic: article.origlink || article.link,
|
||||
payload: article.description,
|
||||
article: article
|
||||
};
|
||||
if (node.ignorefirst === true && node.donefirst === false) {
|
||||
// do nothing
|
||||
}
|
||||
else {
|
||||
node.send(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
feedparser.on('meta', function (meta) {});
|
||||
feedparser.on('end', function () {});
|
||||
};
|
||||
node.interval_id = setInterval(function() { getFeed(); }, node.interval);
|
||||
node.interval_id = setInterval(function() { node.donefirst = true; getFeed(); }, node.interval);
|
||||
getFeed();
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,8 @@
|
||||
"label": {
|
||||
"feedurl": "Feed url",
|
||||
"refresh": "Refresh",
|
||||
"minutes": "minutes"
|
||||
"minutes": "minutes",
|
||||
"ignorefirst": "Ignore any stories older than restart"
|
||||
},
|
||||
"errors": {
|
||||
"badstatuscode": "error - Bad status code",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "node-red-node-feedparser",
|
||||
"version": "0.2.2",
|
||||
"version": "0.3.0",
|
||||
"description": "A Node-RED node to get RSS Atom feeds.",
|
||||
"dependencies": {
|
||||
"feedparser": "^2.2.10",
|
||||
@ -15,7 +15,8 @@
|
||||
"keywords": [
|
||||
"node-red",
|
||||
"atom",
|
||||
"rss"
|
||||
"rss",
|
||||
"feed"
|
||||
],
|
||||
"node-red": {
|
||||
"nodes": {
|
||||
|
Loading…
Reference in New Issue
Block a user