mirror of
https://github.com/Brandon-Rozek/Rozbot.git
synced 2024-11-07 20:30:34 -05:00
23 lines
748 B
JavaScript
23 lines
748 B
JavaScript
|
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);
|
||
|
});
|
||
|
});
|
||
|
}
|