-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStarryKnight.js
More file actions
88 lines (76 loc) · 3.37 KB
/
StarryKnight.js
File metadata and controls
88 lines (76 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
var request = require("request");
var S = require("string");
var cheerio = require("cheerio");
var moment = require("moment");
moment().format();
exports.getUsersLatestTweets = function getUsersLatestTweets(username, callback) {
var tweets = [];
request("https://twitter.com/i/profiles/show/" + username + "/timeline/with_replies?include_available_features=1&include_entities=1", function(error, response, body) {
if (!error && response.statusCode == 200) {
var jsonDoc = JSON.parse(body);
var $ = cheerio.load(jsonDoc.items_html);
$(".original-tweet").each(function(i, el) {
var text = $(el).find(".tweet-text").text();
var tweet_id = $(el).attr("data-tweet-id");
var time = $(el).find(".js-relative-timestamp").attr("data-time");
var relativeTime = moment.unix(time).fromNow();
var obj = {
text: text,
tweet_id: tweet_id,
time: time,
relativeTime: time
};
tweets.push(obj);
});
callback(tweets);
}
});
};
exports.getTweetFaves = function getTweetFaves(id, callback) {
var users = [];
request("https://twitter.com/i/activity/favorited_popup?id=" + id, function(error, response, body) {
if (!error && response.statusCode == 200) {
var jsonDoc = JSON.parse(body);
var favCount = S(jsonDoc.htmlTitle).between("Favorited", "times").trim().s;
var $ = cheerio.load(jsonDoc.htmlUsers);
$(".js-stream-item > .js-actionable-user").each(function(i, el) {
var user = {};
user.username = $(el).attr("data-screen-name");
user.user_name = $(el).find(".user-actions").attr("data-name");
user.user_id = $(el).attr("data-user-id");
user.protected = $(el).find(".user-actions").attr("data-protected") == "true";
user.followers = parseInt($(el).find(".followers-count > strong").text());
users.push(user);
});
var obj = {
count: favCount,
users: users
};
callback(obj);
}
});
};
exports.getTweetRetweets = function getTweetRetweets(id, callback) {
var users = [];
request("https://twitter.com/i/activity/retweeted_popup?id=" + id, function(error, response, body) {
if (!error && response.statusCode == 200) {
var jsonDoc = JSON.parse(body);
var favCount = S(jsonDoc.htmlTitle).between("Retweeted", "times").trim().s;
var $ = cheerio.load(jsonDoc.htmlUsers);
$(".js-stream-item > .js-actionable-user").each(function(i, el) {
var user = {};
user.username = $(el).attr("data-screen-name");
user.user_name = $(el).find(".user-actions").attr("data-name");
user.user_id = $(el).attr("data-user-id");
user.protected = $(el).find(".user-actions").attr("data-protected") == "true";
user.followers = parseInt($(el).find(".followers-count > strong").text());
users.push(user);
});
var obj = {
count: favCount,
users: users
};
callback(obj);
}
});
};