Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@mikowals mikowals commented Jun 22, 2013

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