Skip to content

Instantly share code, notes, and snippets.

@ktiniatros
Created May 11, 2015 12:06
Show Gist options
  • Save ktiniatros/4ca5c1093cda2e8e99b7 to your computer and use it in GitHub Desktop.
Save ktiniatros/4ca5c1093cda2e8e99b7 to your computer and use it in GitHub Desktop.
var request = require('request');
var FeedParser = require('feedparser');
function RSSFetcher( params ) {
this.url = params.url;
}
RSSFetcher.prototype.fetch = function( cb ) {
var my = this;
var items = [];
if( my.url.indexOf('http') < 0 && my.url.indexOf('https') < 0 ) {
cb(new Error( 'Not valid feed url' + my.url ));
return;
}
var req = request(my.url);
var feedparser = new FeedParser( );
req.on('error', function( err ) {
throw new Error(err);
});
req.on('response', function( res ) {
var stream = this;
if( res.statusCode == 200 ) {
stream.pipe(feedparser);
} else {
throw new Error('no good status from request for ' + my.url);
}
});
feedparser.on('error', function( err ) {
console.error('feedparser Error heree', my.url, err);
});
feedparser.on('readable', function( ) {
var item;
while( item = this.read() ) {
items.push(item);
}
});
feedparser.on('end', function( ) {
console.log('Feed parser ended');
});
};
var f =new RSSFetcher({
url: 'https://www.facebook.com/feeds/page.php?format=rss20&id=44015482829'
});
f.fetch();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment