Last active
December 18, 2015 19:39
-
-
Save mikowals/5834696 to your computer and use it in GitHub Desktop.
feedparser debugging for smallpict rss feed
This file contains 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
#! /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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
rearranged code so stream will only pipe to feedparser if statusCode of http response is 200;