@the-convocation/twitter-scraper 0.0.9 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/timeline.js CHANGED
@@ -1,228 +1,234 @@
1
- import { parseProfile } from './profile';
2
- const reHashtag = /\B(\#\S+\b)/g;
3
- const reTwitterUrl = /https:(\/\/t\.co\/([A-Za-z0-9]|[A-Za-z]){10})/g;
4
- const reUsername = /\B(\@\S{1,15}\b)/g;
5
- export function parseTweet(timeline, id) {
6
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
7
- const tweets = (_b = (_a = timeline.globalObjects) === null || _a === void 0 ? void 0 : _a.tweets) !== null && _b !== void 0 ? _b : {};
8
- const tweet = tweets[id];
9
- if (tweet == null || tweet.user_id_str == null) {
10
- return null;
11
- }
12
- const users = (_d = (_c = timeline.globalObjects) === null || _c === void 0 ? void 0 : _c.users) !== null && _d !== void 0 ? _d : {};
13
- const user = users[tweet.user_id_str];
14
- const username = user === null || user === void 0 ? void 0 : user.screen_name;
15
- if (user == null || username == null) {
16
- // TODO: change the return type to a result, and return an error; this shouldn't happen, but we don't know what data we're dealing with.
17
- return null;
18
- }
19
- const tw = {
20
- id,
21
- hashtags: [],
22
- likes: tweet.favorite_count,
23
- permanentUrl: `https://twitter.com/${username}/status/${id}`,
24
- photos: [],
25
- replies: tweet.reply_count,
26
- retweets: tweet.retweet_count,
27
- text: tweet.full_text,
28
- urls: [],
29
- userId: tweet.user_id_str,
30
- username,
31
- videos: [],
32
- };
33
- if (tweet.created_at != null) {
34
- tw.timeParsed = new Date(Date.parse(tweet.created_at));
35
- tw.timestamp = Math.floor(tw.timeParsed.valueOf() / 1000);
36
- }
37
- if (((_e = tweet.place) === null || _e === void 0 ? void 0 : _e.id) != null) {
38
- tw.place = tweet.place;
39
- }
40
- if (tweet.quoted_status_id_str != null) {
41
- const quotedStatus = parseTweet(timeline, tweet.quoted_status_id_str);
42
- if (quotedStatus != null) {
43
- tw.isQuoted = true;
44
- tw.quotedStatus = quotedStatus;
45
- }
46
- }
47
- if (tweet.in_reply_to_status_id_str != null) {
48
- const replyStatus = parseTweet(timeline, tweet.in_reply_to_status_id_str);
49
- if (replyStatus != null) {
50
- tw.isReply = true;
51
- tw.inReplyToStatus = replyStatus;
52
- }
53
- }
54
- if (tweet.retweeted_status_id_str != null) {
55
- const retweetedStatus = parseTweet(timeline, tweet.retweeted_status_id_str);
56
- if (retweetedStatus != null) {
57
- tw.isRetweet = true;
58
- tw.retweetedStatus = retweetedStatus;
59
- }
60
- }
61
- const pinnedTweets = (_f = user.pinned_tweet_ids_str) !== null && _f !== void 0 ? _f : [];
62
- for (const pinned of pinnedTweets) {
63
- if (tweet.conversation_id_str == pinned) {
64
- tw.isPin = true;
65
- break;
66
- }
67
- }
68
- const hashtags = (_h = (_g = tweet.entities) === null || _g === void 0 ? void 0 : _g.hashtags) !== null && _h !== void 0 ? _h : [];
69
- for (const hashtag of hashtags) {
70
- if (hashtag.text != null) {
71
- tw.hashtags.push(hashtag.text);
72
- }
73
- }
74
- const media = (_k = (_j = tweet.extended_entities) === null || _j === void 0 ? void 0 : _j.media) !== null && _k !== void 0 ? _k : [];
75
- for (const m of media) {
76
- if (m.media_url_https == null) {
77
- continue;
78
- }
79
- if (m.type === 'photo') {
80
- tw.photos.push(m.media_url_https);
81
- }
82
- else if (m.type === 'video' && m.id_str != null) {
83
- const video = {
84
- id: m.id_str,
85
- preview: m.media_url_https,
86
- };
87
- let maxBitrate = 0;
88
- const variants = (_m = (_l = m.video_info) === null || _l === void 0 ? void 0 : _l.variants) !== null && _m !== void 0 ? _m : [];
89
- for (const variant of variants) {
90
- const bitrate = variant.bitrate;
91
- if (bitrate != null && bitrate > maxBitrate && variant.url != null) {
92
- let variantUrl = variant.url;
93
- const stringStart = 0;
94
- const tagSuffixIdx = variantUrl.indexOf('?tag=10');
95
- if (tagSuffixIdx !== -1) {
96
- variantUrl = variantUrl.substring(stringStart, tagSuffixIdx + 1);
97
- }
98
- video.url = variantUrl;
99
- maxBitrate = bitrate;
100
- }
101
- }
102
- tw.photos.push(video.preview);
103
- tw.videos.push(video);
104
- }
105
- const sensitive = m.ext_sensitive_media_warning;
106
- if (sensitive != null) {
107
- tw.sensitiveContent =
108
- sensitive.adult_content ||
109
- sensitive.graphic_violence ||
110
- sensitive.other;
111
- }
112
- }
113
- const urls = (_p = (_o = tweet.entities) === null || _o === void 0 ? void 0 : _o.urls) !== null && _p !== void 0 ? _p : [];
114
- for (const url of urls) {
115
- if ((url === null || url === void 0 ? void 0 : url.expanded_url) != null) {
116
- tw.urls.push(url.expanded_url);
117
- }
118
- }
119
- // HTML parsing with regex :)
120
- let html = (_q = tweet.full_text) !== null && _q !== void 0 ? _q : '';
121
- html = html.replace(reHashtag, (hashtag) => {
122
- return `<a href="https://twitter.com/hashtag/${hashtag.replace('#', '')}">${hashtag}</a>`;
123
- });
124
- html = html.replace(reUsername, (username) => {
125
- return `<a href="https://twitter.com/${username[0].replace('@', '')}">${username[0]}</a>`;
126
- });
127
- const foundedMedia = [];
128
- html = html.replace(reTwitterUrl, (tco) => {
129
- var _a, _b, _c, _d;
130
- for (const entity of (_b = (_a = tweet.entities) === null || _a === void 0 ? void 0 : _a.urls) !== null && _b !== void 0 ? _b : []) {
131
- if (tco === entity.url && entity.expanded_url != null) {
132
- return `<a href="${entity.expanded_url}">${tco}</a>`;
133
- }
134
- }
135
- for (const entity of (_d = (_c = tweet.extended_entities) === null || _c === void 0 ? void 0 : _c.media) !== null && _d !== void 0 ? _d : []) {
136
- if (tco === entity.url && entity.media_url_https != null) {
137
- foundedMedia.push(entity.media_url_https);
138
- return `<br><a href="${tco}"><img src="${entity.media_url_https}"/></a>`;
139
- }
140
- }
141
- return tco;
142
- });
143
- for (const url of tw.photos) {
144
- if (foundedMedia.indexOf(url) !== -1) {
145
- continue;
146
- }
147
- html += `<br><img src="${url}"/>`;
148
- }
149
- html = html.replace(/\n/g, '<br>');
150
- tw.html = html;
151
- return tw;
152
- }
153
- export function parseTweets(timeline) {
154
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
155
- let cursor;
156
- let pinnedTweet;
157
- let orderedTweets = [];
158
- for (const instruction of (_b = (_a = timeline.timeline) === null || _a === void 0 ? void 0 : _a.instructions) !== null && _b !== void 0 ? _b : []) {
159
- const pinnedTweetId = (_h = (_g = (_f = (_e = (_d = (_c = instruction.pinEntry) === null || _c === void 0 ? void 0 : _c.entry) === null || _d === void 0 ? void 0 : _d.content) === null || _e === void 0 ? void 0 : _e.item) === null || _f === void 0 ? void 0 : _f.content) === null || _g === void 0 ? void 0 : _g.tweet) === null || _h === void 0 ? void 0 : _h.id;
160
- if (pinnedTweetId != null) {
161
- const tweet = parseTweet(timeline, pinnedTweetId);
162
- if (tweet != null) {
163
- pinnedTweet = tweet;
164
- }
165
- }
166
- for (const entry of (_k = (_j = instruction.addEntries) === null || _j === void 0 ? void 0 : _j.entries) !== null && _k !== void 0 ? _k : []) {
167
- const tweetId = (_p = (_o = (_m = (_l = entry.content) === null || _l === void 0 ? void 0 : _l.item) === null || _m === void 0 ? void 0 : _m.content) === null || _o === void 0 ? void 0 : _o.tweet) === null || _p === void 0 ? void 0 : _p.id;
168
- if (tweetId != null) {
169
- const tweet = parseTweet(timeline, tweetId);
170
- if (tweet != null) {
171
- orderedTweets.push(tweet);
172
- }
173
- }
174
- const operation = (_q = entry.content) === null || _q === void 0 ? void 0 : _q.operation;
175
- if (((_r = operation === null || operation === void 0 ? void 0 : operation.cursor) === null || _r === void 0 ? void 0 : _r.cursorType) === 'Bottom') {
176
- cursor = (_s = operation === null || operation === void 0 ? void 0 : operation.cursor) === null || _s === void 0 ? void 0 : _s.value;
177
- }
178
- }
179
- const operation = (_v = (_u = (_t = instruction.replaceEntry) === null || _t === void 0 ? void 0 : _t.entry) === null || _u === void 0 ? void 0 : _u.content) === null || _v === void 0 ? void 0 : _v.operation;
180
- if (((_w = operation === null || operation === void 0 ? void 0 : operation.cursor) === null || _w === void 0 ? void 0 : _w.cursorType) === 'Bottom') {
181
- cursor = operation.cursor.value;
182
- }
183
- }
184
- if (pinnedTweet != null && orderedTweets.length > 0) {
185
- orderedTweets = [pinnedTweet, ...orderedTweets];
186
- }
187
- return {
188
- tweets: orderedTweets,
189
- next: cursor,
190
- };
191
- }
192
- export function parseUsers(timeline) {
193
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
194
- const users = new Map();
195
- const userObjects = (_b = (_a = timeline.globalObjects) === null || _a === void 0 ? void 0 : _a.users) !== null && _b !== void 0 ? _b : {};
196
- for (const id in userObjects) {
197
- const legacy = userObjects[id];
198
- if (legacy == null) {
199
- continue;
200
- }
201
- const user = parseProfile(legacy);
202
- users.set(id, user);
203
- }
204
- let cursor;
205
- const orderedProfiles = [];
206
- for (const instruction of (_d = (_c = timeline.timeline) === null || _c === void 0 ? void 0 : _c.instructions) !== null && _d !== void 0 ? _d : []) {
207
- for (const entry of (_f = (_e = instruction.addEntries) === null || _e === void 0 ? void 0 : _e.entries) !== null && _f !== void 0 ? _f : []) {
208
- const userId = (_k = (_j = (_h = (_g = entry.content) === null || _g === void 0 ? void 0 : _g.item) === null || _h === void 0 ? void 0 : _h.content) === null || _j === void 0 ? void 0 : _j.user) === null || _k === void 0 ? void 0 : _k.id;
209
- const profile = users.get(userId);
210
- if (profile != null) {
211
- orderedProfiles.push(profile);
212
- }
213
- const operation = (_l = entry.content) === null || _l === void 0 ? void 0 : _l.operation;
214
- if (((_m = operation === null || operation === void 0 ? void 0 : operation.cursor) === null || _m === void 0 ? void 0 : _m.cursorType) === 'Bottom') {
215
- cursor = (_o = operation === null || operation === void 0 ? void 0 : operation.cursor) === null || _o === void 0 ? void 0 : _o.value;
216
- }
217
- }
218
- const operation = (_r = (_q = (_p = instruction.replaceEntry) === null || _p === void 0 ? void 0 : _p.entry) === null || _q === void 0 ? void 0 : _q.content) === null || _r === void 0 ? void 0 : _r.operation;
219
- if (((_s = operation === null || operation === void 0 ? void 0 : operation.cursor) === null || _s === void 0 ? void 0 : _s.cursorType) === 'Bottom') {
220
- cursor = operation.cursor.value;
221
- }
222
- }
223
- return {
224
- profiles: orderedProfiles,
225
- next: cursor,
226
- };
227
- }
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseUsers = exports.parseTweets = exports.parseTweet = void 0;
4
+ const profile_1 = require("./profile");
5
+ const reHashtag = /\B(\#\S+\b)/g;
6
+ const reTwitterUrl = /https:(\/\/t\.co\/([A-Za-z0-9]|[A-Za-z]){10})/g;
7
+ const reUsername = /\B(\@\S{1,15}\b)/g;
8
+ function parseTweet(timeline, id) {
9
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
10
+ const tweets = (_b = (_a = timeline.globalObjects) === null || _a === void 0 ? void 0 : _a.tweets) !== null && _b !== void 0 ? _b : {};
11
+ const tweet = tweets[id];
12
+ if (tweet == null || tweet.user_id_str == null) {
13
+ return null;
14
+ }
15
+ const users = (_d = (_c = timeline.globalObjects) === null || _c === void 0 ? void 0 : _c.users) !== null && _d !== void 0 ? _d : {};
16
+ const user = users[tweet.user_id_str];
17
+ const username = user === null || user === void 0 ? void 0 : user.screen_name;
18
+ if (user == null || username == null) {
19
+ // TODO: change the return type to a result, and return an error; this shouldn't happen, but we don't know what data we're dealing with.
20
+ return null;
21
+ }
22
+ const tw = {
23
+ id,
24
+ hashtags: [],
25
+ likes: tweet.favorite_count,
26
+ permanentUrl: `https://twitter.com/${username}/status/${id}`,
27
+ photos: [],
28
+ replies: tweet.reply_count,
29
+ retweets: tweet.retweet_count,
30
+ text: tweet.full_text,
31
+ urls: [],
32
+ userId: tweet.user_id_str,
33
+ username,
34
+ videos: [],
35
+ };
36
+ if (tweet.created_at != null) {
37
+ tw.timeParsed = new Date(Date.parse(tweet.created_at));
38
+ tw.timestamp = Math.floor(tw.timeParsed.valueOf() / 1000);
39
+ }
40
+ if (((_e = tweet.place) === null || _e === void 0 ? void 0 : _e.id) != null) {
41
+ tw.place = tweet.place;
42
+ }
43
+ if (tweet.quoted_status_id_str != null) {
44
+ const quotedStatus = parseTweet(timeline, tweet.quoted_status_id_str);
45
+ if (quotedStatus != null) {
46
+ tw.isQuoted = true;
47
+ tw.quotedStatus = quotedStatus;
48
+ }
49
+ }
50
+ if (tweet.in_reply_to_status_id_str != null) {
51
+ const replyStatus = parseTweet(timeline, tweet.in_reply_to_status_id_str);
52
+ if (replyStatus != null) {
53
+ tw.isReply = true;
54
+ tw.inReplyToStatus = replyStatus;
55
+ }
56
+ }
57
+ if (tweet.retweeted_status_id_str != null) {
58
+ const retweetedStatus = parseTweet(timeline, tweet.retweeted_status_id_str);
59
+ if (retweetedStatus != null) {
60
+ tw.isRetweet = true;
61
+ tw.retweetedStatus = retweetedStatus;
62
+ }
63
+ }
64
+ const pinnedTweets = (_f = user.pinned_tweet_ids_str) !== null && _f !== void 0 ? _f : [];
65
+ for (const pinned of pinnedTweets) {
66
+ if (tweet.conversation_id_str == pinned) {
67
+ tw.isPin = true;
68
+ break;
69
+ }
70
+ }
71
+ const hashtags = (_h = (_g = tweet.entities) === null || _g === void 0 ? void 0 : _g.hashtags) !== null && _h !== void 0 ? _h : [];
72
+ for (const hashtag of hashtags) {
73
+ if (hashtag.text != null) {
74
+ tw.hashtags.push(hashtag.text);
75
+ }
76
+ }
77
+ const media = (_k = (_j = tweet.extended_entities) === null || _j === void 0 ? void 0 : _j.media) !== null && _k !== void 0 ? _k : [];
78
+ for (const m of media) {
79
+ if (m.media_url_https == null) {
80
+ continue;
81
+ }
82
+ if (m.type === 'photo') {
83
+ tw.photos.push(m.media_url_https);
84
+ }
85
+ else if (m.type === 'video' && m.id_str != null) {
86
+ const video = {
87
+ id: m.id_str,
88
+ preview: m.media_url_https,
89
+ };
90
+ let maxBitrate = 0;
91
+ const variants = (_m = (_l = m.video_info) === null || _l === void 0 ? void 0 : _l.variants) !== null && _m !== void 0 ? _m : [];
92
+ for (const variant of variants) {
93
+ const bitrate = variant.bitrate;
94
+ if (bitrate != null && bitrate > maxBitrate && variant.url != null) {
95
+ let variantUrl = variant.url;
96
+ const stringStart = 0;
97
+ const tagSuffixIdx = variantUrl.indexOf('?tag=10');
98
+ if (tagSuffixIdx !== -1) {
99
+ variantUrl = variantUrl.substring(stringStart, tagSuffixIdx + 1);
100
+ }
101
+ video.url = variantUrl;
102
+ maxBitrate = bitrate;
103
+ }
104
+ }
105
+ tw.photos.push(video.preview);
106
+ tw.videos.push(video);
107
+ }
108
+ const sensitive = m.ext_sensitive_media_warning;
109
+ if (sensitive != null) {
110
+ tw.sensitiveContent =
111
+ sensitive.adult_content ||
112
+ sensitive.graphic_violence ||
113
+ sensitive.other;
114
+ }
115
+ }
116
+ const urls = (_p = (_o = tweet.entities) === null || _o === void 0 ? void 0 : _o.urls) !== null && _p !== void 0 ? _p : [];
117
+ for (const url of urls) {
118
+ if ((url === null || url === void 0 ? void 0 : url.expanded_url) != null) {
119
+ tw.urls.push(url.expanded_url);
120
+ }
121
+ }
122
+ // HTML parsing with regex :)
123
+ let html = (_q = tweet.full_text) !== null && _q !== void 0 ? _q : '';
124
+ html = html.replace(reHashtag, (hashtag) => {
125
+ return `<a href="https://twitter.com/hashtag/${hashtag.replace('#', '')}">${hashtag}</a>`;
126
+ });
127
+ html = html.replace(reUsername, (username) => {
128
+ return `<a href="https://twitter.com/${username[0].replace('@', '')}">${username[0]}</a>`;
129
+ });
130
+ const foundedMedia = [];
131
+ html = html.replace(reTwitterUrl, (tco) => {
132
+ var _a, _b, _c, _d;
133
+ for (const entity of (_b = (_a = tweet.entities) === null || _a === void 0 ? void 0 : _a.urls) !== null && _b !== void 0 ? _b : []) {
134
+ if (tco === entity.url && entity.expanded_url != null) {
135
+ return `<a href="${entity.expanded_url}">${tco}</a>`;
136
+ }
137
+ }
138
+ for (const entity of (_d = (_c = tweet.extended_entities) === null || _c === void 0 ? void 0 : _c.media) !== null && _d !== void 0 ? _d : []) {
139
+ if (tco === entity.url && entity.media_url_https != null) {
140
+ foundedMedia.push(entity.media_url_https);
141
+ return `<br><a href="${tco}"><img src="${entity.media_url_https}"/></a>`;
142
+ }
143
+ }
144
+ return tco;
145
+ });
146
+ for (const url of tw.photos) {
147
+ if (foundedMedia.indexOf(url) !== -1) {
148
+ continue;
149
+ }
150
+ html += `<br><img src="${url}"/>`;
151
+ }
152
+ html = html.replace(/\n/g, '<br>');
153
+ tw.html = html;
154
+ return tw;
155
+ }
156
+ exports.parseTweet = parseTweet;
157
+ function parseTweets(timeline) {
158
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
159
+ let cursor;
160
+ let pinnedTweet;
161
+ let orderedTweets = [];
162
+ for (const instruction of (_b = (_a = timeline.timeline) === null || _a === void 0 ? void 0 : _a.instructions) !== null && _b !== void 0 ? _b : []) {
163
+ const pinnedTweetId = (_h = (_g = (_f = (_e = (_d = (_c = instruction.pinEntry) === null || _c === void 0 ? void 0 : _c.entry) === null || _d === void 0 ? void 0 : _d.content) === null || _e === void 0 ? void 0 : _e.item) === null || _f === void 0 ? void 0 : _f.content) === null || _g === void 0 ? void 0 : _g.tweet) === null || _h === void 0 ? void 0 : _h.id;
164
+ if (pinnedTweetId != null) {
165
+ const tweet = parseTweet(timeline, pinnedTweetId);
166
+ if (tweet != null) {
167
+ pinnedTweet = tweet;
168
+ }
169
+ }
170
+ for (const entry of (_k = (_j = instruction.addEntries) === null || _j === void 0 ? void 0 : _j.entries) !== null && _k !== void 0 ? _k : []) {
171
+ const tweetId = (_p = (_o = (_m = (_l = entry.content) === null || _l === void 0 ? void 0 : _l.item) === null || _m === void 0 ? void 0 : _m.content) === null || _o === void 0 ? void 0 : _o.tweet) === null || _p === void 0 ? void 0 : _p.id;
172
+ if (tweetId != null) {
173
+ const tweet = parseTweet(timeline, tweetId);
174
+ if (tweet != null) {
175
+ orderedTweets.push(tweet);
176
+ }
177
+ }
178
+ const operation = (_q = entry.content) === null || _q === void 0 ? void 0 : _q.operation;
179
+ if (((_r = operation === null || operation === void 0 ? void 0 : operation.cursor) === null || _r === void 0 ? void 0 : _r.cursorType) === 'Bottom') {
180
+ cursor = (_s = operation === null || operation === void 0 ? void 0 : operation.cursor) === null || _s === void 0 ? void 0 : _s.value;
181
+ }
182
+ }
183
+ const operation = (_v = (_u = (_t = instruction.replaceEntry) === null || _t === void 0 ? void 0 : _t.entry) === null || _u === void 0 ? void 0 : _u.content) === null || _v === void 0 ? void 0 : _v.operation;
184
+ if (((_w = operation === null || operation === void 0 ? void 0 : operation.cursor) === null || _w === void 0 ? void 0 : _w.cursorType) === 'Bottom') {
185
+ cursor = operation.cursor.value;
186
+ }
187
+ }
188
+ if (pinnedTweet != null && orderedTweets.length > 0) {
189
+ orderedTweets = [pinnedTweet, ...orderedTweets];
190
+ }
191
+ return {
192
+ tweets: orderedTweets,
193
+ next: cursor,
194
+ };
195
+ }
196
+ exports.parseTweets = parseTweets;
197
+ function parseUsers(timeline) {
198
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
199
+ const users = new Map();
200
+ const userObjects = (_b = (_a = timeline.globalObjects) === null || _a === void 0 ? void 0 : _a.users) !== null && _b !== void 0 ? _b : {};
201
+ for (const id in userObjects) {
202
+ const legacy = userObjects[id];
203
+ if (legacy == null) {
204
+ continue;
205
+ }
206
+ const user = (0, profile_1.parseProfile)(legacy);
207
+ users.set(id, user);
208
+ }
209
+ let cursor;
210
+ const orderedProfiles = [];
211
+ for (const instruction of (_d = (_c = timeline.timeline) === null || _c === void 0 ? void 0 : _c.instructions) !== null && _d !== void 0 ? _d : []) {
212
+ for (const entry of (_f = (_e = instruction.addEntries) === null || _e === void 0 ? void 0 : _e.entries) !== null && _f !== void 0 ? _f : []) {
213
+ const userId = (_k = (_j = (_h = (_g = entry.content) === null || _g === void 0 ? void 0 : _g.item) === null || _h === void 0 ? void 0 : _h.content) === null || _j === void 0 ? void 0 : _j.user) === null || _k === void 0 ? void 0 : _k.id;
214
+ const profile = users.get(userId);
215
+ if (profile != null) {
216
+ orderedProfiles.push(profile);
217
+ }
218
+ const operation = (_l = entry.content) === null || _l === void 0 ? void 0 : _l.operation;
219
+ if (((_m = operation === null || operation === void 0 ? void 0 : operation.cursor) === null || _m === void 0 ? void 0 : _m.cursorType) === 'Bottom') {
220
+ cursor = (_o = operation === null || operation === void 0 ? void 0 : operation.cursor) === null || _o === void 0 ? void 0 : _o.value;
221
+ }
222
+ }
223
+ const operation = (_r = (_q = (_p = instruction.replaceEntry) === null || _p === void 0 ? void 0 : _p.entry) === null || _q === void 0 ? void 0 : _q.content) === null || _r === void 0 ? void 0 : _r.operation;
224
+ if (((_s = operation === null || operation === void 0 ? void 0 : operation.cursor) === null || _s === void 0 ? void 0 : _s.cursorType) === 'Bottom') {
225
+ cursor = operation.cursor.value;
226
+ }
227
+ }
228
+ return {
229
+ profiles: orderedProfiles,
230
+ next: cursor,
231
+ };
232
+ }
233
+ exports.parseUsers = parseUsers;
228
234
  //# sourceMappingURL=timeline.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"timeline.js","sourceRoot":"","sources":["../src/timeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,YAAY,EAAW,MAAM,WAAW,CAAC;AAuJjE,MAAM,SAAS,GAAG,cAAc,CAAC;AACjC,MAAM,YAAY,GAAG,gDAAgD,CAAC;AACtE,MAAM,UAAU,GAAG,mBAAmB,CAAC;AAEvC,MAAM,UAAU,UAAU,CAAC,QAAqB,EAAE,EAAU;;IAC1D,MAAM,MAAM,GAAG,MAAA,MAAA,QAAQ,CAAC,aAAa,0CAAE,MAAM,mCAAI,EAAE,CAAC;IACpD,MAAM,KAAK,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;IACzB,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,CAA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AT,SAAS,CAAE,MAAM,0CAAE,UAAU,MAAK,QAAQ,EAAE;gBAC9C,MAAM,GAAG,MAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,MAAM,0CAAE,KAAK,CAAC;aACnC;SACF;QAED,MAAM,SAAS,GAAG,MAAA,MAAA,MAAA,WAAW,CAAC,YAAY,0CAAE,KAAK,0CAAE,OAAO,0CAAE,SAAS,CAAC;QACtE,IAAI,CAAA,MAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,MAAM,0CAAE,UAAU,MAAK,QAAQ,EAAE;YAC9C,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC;SACjC;KACF;IAED,OAAO;QACL,QAAQ,EAAE,eAAe;QACzB,IAAI,EAAE,MAAM;KACb,CAAC;AACJ,CAAC;AAxCD,gCAwCC"}
package/dist/trends.js CHANGED
@@ -1,46 +1,50 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { addApiParams, requestApi } from './api';
11
- export function getTrends(auth) {
12
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
13
- return __awaiter(this, void 0, void 0, function* () {
14
- const params = new URLSearchParams();
15
- addApiParams(params, false);
16
- params.set('count', '20');
17
- params.set('candidate_source', 'trends');
18
- params.set('include_page_configuration', 'false');
19
- params.set('entity_tokens', 'false');
20
- const res = yield requestApi(`https://twitter.com/i/api/2/guide.json?${params.toString()}`, auth);
21
- if (!res.success) {
22
- throw res.err;
23
- }
24
- const instructions = (_b = (_a = res.value.timeline) === null || _a === void 0 ? void 0 : _a.instructions) !== null && _b !== void 0 ? _b : [];
25
- if (instructions.length < 2) {
26
- throw new Error('No trend entries found.');
27
- }
28
- // Some of this is silly, but for now we're assuming we know nothing about the
29
- // data, and that anything can be missing. Go has non-nilable strings and empty
30
- // slices are nil, so it largely doesn't need to worry about this.
31
- const entries = (_d = (_c = instructions[1].addEntries) === null || _c === void 0 ? void 0 : _c.entries) !== null && _d !== void 0 ? _d : [];
32
- if (entries.length < 2) {
33
- throw new Error('No trend entries found.');
34
- }
35
- const items = (_g = (_f = (_e = entries[1].content) === null || _e === void 0 ? void 0 : _e.timelineModule) === null || _f === void 0 ? void 0 : _f.items) !== null && _g !== void 0 ? _g : [];
36
- const trends = [];
37
- for (const item of items) {
38
- const trend = (_o = (_m = (_l = (_k = (_j = (_h = item.item) === null || _h === void 0 ? void 0 : _h.clientEventInfo) === null || _j === void 0 ? void 0 : _j.details) === null || _k === void 0 ? void 0 : _k.guideDetails) === null || _l === void 0 ? void 0 : _l.transparentGuideDetails) === null || _m === void 0 ? void 0 : _m.trendMetadata) === null || _o === void 0 ? void 0 : _o.trendName;
39
- if (trend != null) {
40
- trends.push(trend);
41
- }
42
- }
43
- return trends;
44
- });
45
- }
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getTrends = void 0;
13
+ const api_1 = require("./api");
14
+ function getTrends(auth) {
15
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ const params = new URLSearchParams();
18
+ (0, api_1.addApiParams)(params, false);
19
+ params.set('count', '20');
20
+ params.set('candidate_source', 'trends');
21
+ params.set('include_page_configuration', 'false');
22
+ params.set('entity_tokens', 'false');
23
+ const res = yield (0, api_1.requestApi)(`https://twitter.com/i/api/2/guide.json?${params.toString()}`, auth);
24
+ if (!res.success) {
25
+ throw res.err;
26
+ }
27
+ const instructions = (_b = (_a = res.value.timeline) === null || _a === void 0 ? void 0 : _a.instructions) !== null && _b !== void 0 ? _b : [];
28
+ if (instructions.length < 2) {
29
+ throw new Error('No trend entries found.');
30
+ }
31
+ // Some of this is silly, but for now we're assuming we know nothing about the
32
+ // data, and that anything can be missing. Go has non-nilable strings and empty
33
+ // slices are nil, so it largely doesn't need to worry about this.
34
+ const entries = (_d = (_c = instructions[1].addEntries) === null || _c === void 0 ? void 0 : _c.entries) !== null && _d !== void 0 ? _d : [];
35
+ if (entries.length < 2) {
36
+ throw new Error('No trend entries found.');
37
+ }
38
+ const items = (_g = (_f = (_e = entries[1].content) === null || _e === void 0 ? void 0 : _e.timelineModule) === null || _f === void 0 ? void 0 : _f.items) !== null && _g !== void 0 ? _g : [];
39
+ const trends = [];
40
+ for (const item of items) {
41
+ const trend = (_o = (_m = (_l = (_k = (_j = (_h = item.item) === null || _h === void 0 ? void 0 : _h.clientEventInfo) === null || _j === void 0 ? void 0 : _j.details) === null || _k === void 0 ? void 0 : _k.guideDetails) === null || _l === void 0 ? void 0 : _l.transparentGuideDetails) === null || _m === void 0 ? void 0 : _m.trendMetadata) === null || _o === void 0 ? void 0 : _o.trendName;
42
+ if (trend != null) {
43
+ trends.push(trend);
44
+ }
45
+ }
46
+ return trends;
47
+ });
48
+ }
49
+ exports.getTrends = getTrends;
46
50
  //# sourceMappingURL=trends.js.map