Last active
January 16, 2018 18:09
-
-
Save scripting/c3eab6e60073678325593c20c1f9fece to your computer and use it in GitHub Desktop.
New way to read XML feeds in River5, see first comment for pointer to context
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function readXmlFeed (urlfeed) { //1/16/18 by DW | |
//Instead of processing items as they come in, gather them into an array, and process them at the end. | |
var req = myRequestCall (urlfeed); | |
var feedparser = new FeedParser (); | |
var feedItems = new Array (); | |
req.on ("response", function (response) { | |
var stream = this; | |
serverStats.ctActiveThreads--; | |
if (response.statusCode == 200) { | |
stream.pipe (feedparser); | |
} | |
else { | |
feedError ("readFeed: response.statusCode == " + response.statusCode); | |
} | |
}); | |
req.on ("error", function (res) { | |
feedError (); | |
}); | |
feedparser.on ("readable", function () { | |
try { | |
var item = this.read (), flnew; | |
if (item !== null) { //2/9/17 by DW | |
processFeedItem (item); | |
feedItems.push (item); | |
} | |
} | |
catch (err) { | |
myConsoleLog ("readXmlFeed: error == " + err.message); | |
} | |
}); | |
feedparser.on ("error", function () { | |
feedError (); | |
}); | |
feedparser.on ("end", function () { | |
getFeedRiver (urlfeed, function (jstruct) { //make sure the feed's river is loaded in cache | |
myConsoleLog ("readXmlFeed: feedItems.length == " + feedItems.length); | |
for (var i = 0; i < feedItems.length; i++) { | |
processFeedItem (feedItems [i]); | |
} | |
finishFeedProcessing (); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Context --
scripting/river5#14 (comment)
Dave