Rozbot/lib/helpers/parseTwitter.js

23 lines
748 B
JavaScript
Raw Normal View History

2016-07-11 23:24:15 -04:00
var cheerio = require('../promise/cheerio.js');
var promise = require('promise-polyfill');
module.exports = function(html) {
return new promise(function(resolve, reject) {
cheerio(html).then(function($) {
var tweets = [];
var tweetsContainer = $('.tweet');
var tweetsToShow = Math.min(5, tweetsContainer.length - 1);
for (var i = 0; i < tweetsToShow; i++) {
tweets.push($('.tweet').children().find('.fullname').eq(i).text() + " (" + $('.tweet').children().find('.username').eq(i).text() + ")" + ": " + $('.tweet').children().find('.tweet-text').eq(i).text())
}
if (tweets.length > 0) {
resolve(tweets);
} else {
reject("No tweets were found.")
}
}).catch(function(error) {
reject(error);
});
});
}