Created
December 12, 2014 12:47
-
-
Save AYLIEN/a9fa84020ece74354805 to your computer and use it in GitHub Desktop.
HN Top 5 Stories with Summary
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
var AYLIENTextAPI = require('aylien_textapi'), | |
request = require('request'), | |
xml2js = require('xml2js'); | |
var textapi = new AYLIENTextAPI({ | |
application_id: 'YourApplicationId', | |
application_key: 'YourApplicationKey' | |
}); | |
var parser = new xml2js.Parser(); | |
parser.addListener('end', function(result) { | |
var items = result.rss.channel[0].item; | |
items.slice(0,5).forEach(function(item) { | |
var title = item.title[0]; | |
var link = item.link[0]; | |
textapi.summarize(link, function(error, result) { | |
if (error === null) { | |
console.log(title + ":"); | |
var i = 0; | |
result.sentences.forEach(function(sent) { | |
console.log(++i + ") " + sent); | |
}); | |
console.log("=========="); | |
} else { | |
console.log(error); | |
} | |
}); | |
}); | |
}); | |
request('http://news.ycombinator.com/rss', function (error, response, body) { | |
if (error === null) { | |
parser.parseString(body); | |
} else { | |
console.log(error); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment