diff --git a/social/feedparser/32-feedparse.html b/social/feedparser/32-feedparse.html index 1a9c4770..89aeccc9 100644 --- a/social/feedparser/32-feedparse.html +++ b/social/feedparser/32-feedparse.html @@ -1,4 +1,8 @@ diff --git a/social/feedparser/32-feedparse.js b/social/feedparser/32-feedparse.js index 9feeeba8..3d162c20 100644 --- a/social/feedparser/32-feedparse.js +++ b/social/feedparser/32-feedparse.js @@ -1,9 +1,7 @@ module.exports = function(RED) { "use strict"; - var FeedParser = require("feedparser"); - var request = require("request"); - var url = require('url'); + const { parseFeed } = require('@rowanmanning/feed-parser'); function FeedParseNode(n) { RED.nodes.createNode(this,n); @@ -12,58 +10,49 @@ module.exports = function(RED) { this.interval = (parseInt(n.interval)||15) * 60000; this.interval_id = null; this.ignorefirst = n.ignorefirst || false; + this.sendarray = n.sendarray || 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"),RED._("feedparse.errors.invalidurl")); - } - else { - var getFeed = function() { - var req = request(node.url, {timeout:10000, pool:false}); - //req.setMaxListeners(50); - req.setHeader('user-agent', 'Mozilla/5.0 (Node-RED)'); - req.setHeader('accept', 'application/rss+xml,text/html,application/xhtml+xml,application/xml'); - var feedparser = new FeedParser(); + async function getFeed() { + const response = await fetch(node.url); + if (response.status !== 200) { + node.error("Bad Feed: "+node.url, err) + node.status({fill:"red",shape:"dot",text:response.status+": "+RED._("feedparse.errors.badstatuscode")}); + return; + } + const feed = parseFeed(await response.text()); + if (node.sendarray === true) { + var msg = JSON.parse(JSON.stringify(feed)); + node.send(msg); + } + else { + for (let a=0; a + - link - *string* - URL link to article. +- feed - *string* - Top level feed link, as configured. + - article - *object* - Complete article object. + +The msg.article property contains the complete article object, + which has properties such as .title, .description, + .image and so on. + +If you select to return a single object - the only thing returned is the + complete original response, which has different properties from those listed above. + +You can set the polling time in minutes. Defaults to 15 minutes. The refresh interval cannot be greater than 35790 minutes (approx 24.8 days) diff --git a/social/feedparser/locales/en-US/32-feedparse.html b/social/feedparser/locales/en-US/32-feedparse.html index 0f27140d..ac658c04 100644 --- a/social/feedparser/locales/en-US/32-feedparse.html +++ b/social/feedparser/locales/en-US/32-feedparse.html @@ -3,13 +3,20 @@

Outputs

topic string
-
Original article link
+
Title of article.
payload string
-
Description
+
Description of article.
+
link string
+
URL link to article.
+
feed string
+
Top level feed link, as configured.
article object
-
Complete article object
+
Complete article object.

The msg.article property contains the complete article object, - which has properties such as .title, .summary, .date and so on.

+ which has properties such as .title, .description, + .image and so on.

+

If you select to return a single object - the only thing returned is the + complete original response, which has different properties from those listed above.

The refresh interval cannot be greater than 35790 minutes (approx 24.8 days). diff --git a/social/feedparser/locales/en-US/32-feedparse.json b/social/feedparser/locales/en-US/32-feedparse.json index c2be15ee..2d639587 100644 --- a/social/feedparser/locales/en-US/32-feedparse.json +++ b/social/feedparser/locales/en-US/32-feedparse.json @@ -5,12 +5,14 @@ "feedurl": "Feed url", "refresh": "Refresh", "minutes": "minutes", - "ignorefirst": "Ignore any stories older than restart" + "ignorefirst": "Ignore any stories older than restart", + "sendarray": "Send response as a single object" }, "errors": { "badstatuscode": "error - Bad status code", "invalidurl": "Invalid url", - "invalidinterval": "Repeat interval too large" + "invalidinterval": "Repeat interval too large", + "badparse": "error - Bad feed parse" } } } diff --git a/social/feedparser/package.json b/social/feedparser/package.json index c729aa53..369ad83e 100644 --- a/social/feedparser/package.json +++ b/social/feedparser/package.json @@ -1,10 +1,9 @@ { "name": "node-red-node-feedparser", - "version": "0.3.0", + "version": "1.0.0", "description": "A Node-RED node to get RSS Atom feeds.", "dependencies": { - "feedparser": "^2.2.10", - "request": "^2.88.2" + "@rowanmanning/feed-parser": "^2.1.1" }, "repository": { "type": "git",