Skip to content

Instantly share code, notes, and snippets.

@AYLIEN
Created December 12, 2014 12:47
Show Gist options
  • Save AYLIEN/a9fa84020ece74354805 to your computer and use it in GitHub Desktop.
Save AYLIEN/a9fa84020ece74354805 to your computer and use it in GitHub Desktop.
HN Top 5 Stories with Summary
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