Skip to content

Instantly share code, notes, and snippets.

@mikowals
Last active December 18, 2015 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mikowals/5834696 to your computer and use it in GitHub Desktop.
Save mikowals/5834696 to your computer and use it in GitHub Desktop.
feedparser debugging for smallpict rss feed
#! /usr/bin/env node
var feedparser = require( 'feedparser' );
var request = require( 'request' );
var feedTest = function ( url ) {
var statusCode;
var object = {};
object.articles = [];
var r = request(url, {timeout: 6000})
.on( 'error' , function ( error ) {
console.log(url + " : " + error);
})
.on ( 'response' , function ( response ) {
if ( response.statusCode !== 200 ){
console.log( "http statuscode = " + response.statusCode );
}
else {
r.pipe(new feedparser())
.on('error', function(err ){
console.log(url + " : " + err);
object = null;
})
.on ( 'meta', function ( meta ){
if ( meta ) object.meta = meta;
})
.on('readable', function(){
var stream = this, item;
while (item = stream.read()) {
object.articles.push ( item );
}
})
.on( 'end', function() {
console.log ( JSON.stringify( url ) );
console.log ( JSON.stringify( object && object.meta.title ) );
});
}
})
}
var url = "http://dave.smallpict.com/rss.xml";
feedTest ( url );
var url2 = "http://scripting.com/rss.xml";
feedTest ( url2 );
@mikowals
Copy link
Author

rearranged code so stream will only pipe to feedparser if statusCode of http response is 200;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment