Skip to content

Instantly share code, notes, and snippets.

@danmactough
Forked from mikowals/feedparser.js
Last active December 18, 2015 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danmactough/5834897 to your computer and use it in GitHub Desktop.
Save danmactough/5834897 to your computer and use it in GitHub Desktop.
#! /usr/bin/env node
var feedparser = require( 'feedparser' );
var request = require( 'request' );
var feedTest = function (url){
var object = {};
object.articles =[];
request( url, {timeout: 20000}, function(error, resp, body){
if (error){
console.log(url + " : " + error);
}
else {
console.log(resp.statusCode);
console.log(body);
}
})
.pipe(new feedparser())
.on('error', function(err){
console.log(url + " : " + err);
object = null;
})
.on ( 'meta', function ( 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( object && object.meta.title ) );
});
}
var url = "http://dave.smallpict.com/rss.xml";
feedTest ( url );
/** output
* http://dave.smallpict.com/rss.xml : Error: Not a feed
* null
* */
// var url2 = "http://scripting.com/rss.xml";
// feedTest ( url2 );
/** output
* "Dave Winer"
* */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment