@the-convocation/twitter-scraper 0.0.8 → 0.1.0

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,228 @@
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
+ 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
+ }
228
228
  //# sourceMappingURL=timeline.js.map
package/dist/trends.js CHANGED
@@ -1,46 +1,46 @@
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
+ 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
+ }
46
46
  //# sourceMappingURL=trends.js.map