@the-convocation/twitter-scraper 0.1.5 → 0.3.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/_module.d.ts +1 -1
- package/dist/_module.d.ts.map +1 -1
- package/dist/api.d.ts +19 -3
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +61 -45
- package/dist/api.js.map +1 -1
- package/dist/auth-user.d.ts +2 -3
- package/dist/auth-user.d.ts.map +1 -1
- package/dist/auth-user.js +176 -176
- package/dist/auth-user.js.map +1 -1
- package/dist/auth.d.ts +4 -7
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +44 -48
- package/dist/auth.js.map +1 -1
- package/dist/errors.d.ts +3 -4
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/profile.d.ts.map +1 -1
- package/dist/profile.js +56 -67
- package/dist/profile.js.map +1 -1
- package/dist/requests.d.ts +9 -0
- package/dist/requests.d.ts.map +1 -0
- package/dist/requests.js +26 -0
- package/dist/requests.js.map +1 -0
- package/dist/scraper.d.ts +13 -13
- package/dist/scraper.d.ts.map +1 -1
- package/dist/scraper.js +49 -69
- package/dist/scraper.js.map +1 -1
- package/dist/search.d.ts +4 -4
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +62 -62
- package/dist/search.js.map +1 -1
- package/dist/timeline-async.d.ts +2 -2
- package/dist/timeline-async.d.ts.map +1 -1
- package/dist/timeline-async.js +34 -50
- package/dist/timeline-async.js.map +1 -1
- package/dist/timeline-search.d.ts +20 -0
- package/dist/timeline-search.d.ts.map +1 -0
- package/dist/timeline-search.js +75 -0
- package/dist/timeline-search.js.map +1 -0
- package/dist/timeline-tweet-util.d.ts +9 -0
- package/dist/timeline-tweet-util.d.ts.map +1 -0
- package/dist/timeline-tweet-util.js +102 -0
- package/dist/timeline-tweet-util.js.map +1 -0
- package/dist/{timeline.d.ts → timeline-v1.d.ts} +36 -9
- package/dist/timeline-v1.d.ts.map +1 -0
- package/dist/timeline-v1.js +181 -0
- package/dist/timeline-v1.js.map +1 -0
- package/dist/timeline-v2.d.ts +61 -0
- package/dist/timeline-v2.d.ts.map +1 -0
- package/dist/timeline-v2.js +194 -0
- package/dist/timeline-v2.js.map +1 -0
- package/dist/trends.js +31 -42
- package/dist/trends.js.map +1 -1
- package/dist/tweets.d.ts +12 -6
- package/dist/tweets.d.ts.map +1 -1
- package/dist/tweets.js +79 -86
- package/dist/tweets.js.map +1 -1
- package/dist/type-util.d.ts +6 -0
- package/dist/type-util.d.ts.map +1 -0
- package/dist/type-util.js +14 -0
- package/dist/type-util.js.map +1 -0
- package/package.json +11 -2
- package/dist/timeline.d.ts.map +0 -1
- package/dist/timeline.js +0 -280
- package/dist/timeline.js.map +0 -1
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseThreadedConversation = exports.parseTimelineTweetsV2 = exports.parseLegacyTweet = void 0;
|
|
4
|
+
const timeline_tweet_util_1 = require("./timeline-tweet-util");
|
|
5
|
+
const type_util_1 = require("./type-util");
|
|
6
|
+
function parseLegacyTweet(user, tweet) {
|
|
7
|
+
if (tweet == null) {
|
|
8
|
+
return {
|
|
9
|
+
success: false,
|
|
10
|
+
err: new Error('Tweet was not found in the timeline object.'),
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
if (user == null) {
|
|
14
|
+
return {
|
|
15
|
+
success: false,
|
|
16
|
+
err: new Error('User was not found in the timeline object.'),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const hashtags = tweet.entities?.hashtags ?? [];
|
|
20
|
+
const mentions = tweet.entities?.user_mentions ?? [];
|
|
21
|
+
const media = tweet.extended_entities?.media ?? [];
|
|
22
|
+
const pinnedTweets = new Set(user.pinned_tweet_ids_str ?? []);
|
|
23
|
+
const urls = tweet.entities?.urls ?? [];
|
|
24
|
+
const { photos, videos, sensitiveContent } = (0, timeline_tweet_util_1.parseMediaGroups)(media);
|
|
25
|
+
if (tweet.id_str == null) {
|
|
26
|
+
return {
|
|
27
|
+
success: false,
|
|
28
|
+
err: new Error('Tweet ID was not found in object.'),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const tw = {
|
|
32
|
+
conversationId: tweet.conversation_id_str,
|
|
33
|
+
id: tweet.id_str,
|
|
34
|
+
hashtags: hashtags
|
|
35
|
+
.filter((0, type_util_1.isFieldDefined)('text'))
|
|
36
|
+
.map((hashtag) => hashtag.text),
|
|
37
|
+
likes: tweet.favorite_count,
|
|
38
|
+
mentions: mentions.filter((0, type_util_1.isFieldDefined)('id_str')).map((mention) => ({
|
|
39
|
+
id: mention.id_str,
|
|
40
|
+
username: mention.screen_name,
|
|
41
|
+
name: mention.name,
|
|
42
|
+
})),
|
|
43
|
+
name: user.name,
|
|
44
|
+
permanentUrl: `https://twitter.com/${user.screen_name}/status/${tweet.id_str}`,
|
|
45
|
+
photos,
|
|
46
|
+
replies: tweet.reply_count,
|
|
47
|
+
retweets: tweet.retweet_count,
|
|
48
|
+
text: tweet.full_text,
|
|
49
|
+
thread: [],
|
|
50
|
+
urls: urls
|
|
51
|
+
.filter((0, type_util_1.isFieldDefined)('expanded_url'))
|
|
52
|
+
.map((url) => url.expanded_url),
|
|
53
|
+
userId: tweet.user_id_str,
|
|
54
|
+
username: user.screen_name,
|
|
55
|
+
videos,
|
|
56
|
+
};
|
|
57
|
+
if (tweet.created_at) {
|
|
58
|
+
tw.timeParsed = new Date(Date.parse(tweet.created_at));
|
|
59
|
+
tw.timestamp = Math.floor(tw.timeParsed.valueOf() / 1000);
|
|
60
|
+
}
|
|
61
|
+
if (tweet.place?.id) {
|
|
62
|
+
tw.place = tweet.place;
|
|
63
|
+
}
|
|
64
|
+
if (tweet.quoted_status_id_str) {
|
|
65
|
+
tw.isQuoted = true;
|
|
66
|
+
tw.quotedStatusId = tweet.quoted_status_id_str;
|
|
67
|
+
}
|
|
68
|
+
if (tweet.in_reply_to_status_id_str) {
|
|
69
|
+
tw.isReply = true;
|
|
70
|
+
tw.inReplyToStatusId = tweet.in_reply_to_status_id_str;
|
|
71
|
+
}
|
|
72
|
+
if (tweet.retweeted_status_id_str || tweet.retweeted_status_result?.result) {
|
|
73
|
+
tw.isRetweet = true;
|
|
74
|
+
tw.retweetedStatusId = tweet.retweeted_status_id_str;
|
|
75
|
+
if (tweet.retweeted_status_result?.result) {
|
|
76
|
+
const retweetedStatusResult = parseLegacyTweet(tweet.retweeted_status_result.result.core?.user_results?.result?.legacy, tweet.retweeted_status_result.result.legacy);
|
|
77
|
+
if (retweetedStatusResult.success) {
|
|
78
|
+
tw.retweetedStatus = retweetedStatusResult.tweet;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const views = parseInt(tweet.ext_views?.count ?? '');
|
|
83
|
+
if (!isNaN(views)) {
|
|
84
|
+
tw.views = views;
|
|
85
|
+
}
|
|
86
|
+
if (pinnedTweets.has(tweet.id_str)) {
|
|
87
|
+
// TODO: Update tests so this can be assigned at the tweet declaration
|
|
88
|
+
tw.isPin = true;
|
|
89
|
+
}
|
|
90
|
+
if (sensitiveContent) {
|
|
91
|
+
// TODO: Update tests so this can be assigned at the tweet declaration
|
|
92
|
+
tw.sensitiveContent = true;
|
|
93
|
+
}
|
|
94
|
+
tw.html = (0, timeline_tweet_util_1.reconstructTweetHtml)(tweet, tw.photos, tw.videos);
|
|
95
|
+
return { success: true, tweet: tw };
|
|
96
|
+
}
|
|
97
|
+
exports.parseLegacyTweet = parseLegacyTweet;
|
|
98
|
+
function parseResult(result) {
|
|
99
|
+
if (result?.legacy && result.note_tweet?.note_tweet_results?.result?.text) {
|
|
100
|
+
result.legacy.full_text = result.note_tweet.note_tweet_results.result.text;
|
|
101
|
+
}
|
|
102
|
+
const tweetResult = parseLegacyTweet(result?.core?.user_results?.result?.legacy, result?.legacy);
|
|
103
|
+
if (!tweetResult.success) {
|
|
104
|
+
return tweetResult;
|
|
105
|
+
}
|
|
106
|
+
if (!tweetResult.tweet.views && result?.views?.count) {
|
|
107
|
+
const views = parseInt(result.views.count);
|
|
108
|
+
if (!isNaN(views)) {
|
|
109
|
+
tweetResult.tweet.views = views;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (result?.quoted_status_result?.result) {
|
|
113
|
+
const quotedTweetResult = parseResult(result.quoted_status_result.result);
|
|
114
|
+
if (quotedTweetResult.success) {
|
|
115
|
+
tweetResult.tweet.quotedStatus = quotedTweetResult.tweet;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return tweetResult;
|
|
119
|
+
}
|
|
120
|
+
function parseTimelineTweetsV2(timeline) {
|
|
121
|
+
let cursor;
|
|
122
|
+
const tweets = [];
|
|
123
|
+
const instructions = timeline.data?.user?.result?.timeline_v2?.timeline?.instructions ?? [];
|
|
124
|
+
for (const instruction of instructions) {
|
|
125
|
+
for (const entry of instruction.entries ?? []) {
|
|
126
|
+
if (entry.content?.cursorType === 'Bottom') {
|
|
127
|
+
cursor = entry.content.value;
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (entry.content?.itemContent?.tweet_results?.result?.__typename ===
|
|
131
|
+
'Tweet') {
|
|
132
|
+
const tweetResult = parseResult(entry.content.itemContent.tweet_results.result);
|
|
133
|
+
if (tweetResult.success) {
|
|
134
|
+
tweets.push(tweetResult.tweet);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return { tweets: [], next: cursor };
|
|
140
|
+
}
|
|
141
|
+
exports.parseTimelineTweetsV2 = parseTimelineTweetsV2;
|
|
142
|
+
function parseThreadedConversation(conversation) {
|
|
143
|
+
const tweets = [];
|
|
144
|
+
const instructions = conversation.data?.threaded_conversation_with_injections_v2?.instructions ??
|
|
145
|
+
[];
|
|
146
|
+
for (const instruction of instructions) {
|
|
147
|
+
for (const entry of instruction.entries ?? []) {
|
|
148
|
+
if (entry.content?.itemContent?.tweet_results?.result?.__typename ===
|
|
149
|
+
'Tweet') {
|
|
150
|
+
const tweetResult = parseResult(entry.content.itemContent.tweet_results.result);
|
|
151
|
+
if (tweetResult.success) {
|
|
152
|
+
if (entry.content.itemContent.tweetDisplayType === 'SelfThread') {
|
|
153
|
+
tweetResult.tweet.isSelfThread = true;
|
|
154
|
+
}
|
|
155
|
+
tweets.push(tweetResult.tweet);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
for (const item of entry.content?.items ?? []) {
|
|
159
|
+
if (item.item?.itemContent?.tweet_results?.result?.__typename === 'Tweet') {
|
|
160
|
+
const tweetResult = parseResult(item.item.itemContent.tweet_results.result);
|
|
161
|
+
if (tweetResult.success) {
|
|
162
|
+
if (item.item.itemContent.tweetDisplayType === 'SelfThread') {
|
|
163
|
+
tweetResult.tweet.isSelfThread = true;
|
|
164
|
+
}
|
|
165
|
+
tweets.push(tweetResult.tweet);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
for (const tweet of tweets) {
|
|
172
|
+
if (tweet.inReplyToStatusId) {
|
|
173
|
+
for (const parentTweet of tweets) {
|
|
174
|
+
if (parentTweet.id === tweet.inReplyToStatusId) {
|
|
175
|
+
tweet.inReplyToStatus = parentTweet;
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (tweet.isSelfThread && tweet.conversationId === tweet.id) {
|
|
181
|
+
for (const childTweet of tweets) {
|
|
182
|
+
if (childTweet.isSelfThread && childTweet.id !== tweet.id) {
|
|
183
|
+
tweet.thread.push(childTweet);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (tweet.thread.length === 0) {
|
|
187
|
+
tweet.isSelfThread = false;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return tweets;
|
|
192
|
+
}
|
|
193
|
+
exports.parseThreadedConversation = parseThreadedConversation;
|
|
194
|
+
//# sourceMappingURL=timeline-v2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeline-v2.js","sourceRoot":"","sources":["../src/timeline-v2.ts"],"names":[],"mappings":";;;AACA,+DAA+E;AAQ/E,2CAA6C;AA6D7C,SAAgB,gBAAgB,CAC9B,IAAoB,EACpB,KAAsB;IAEtB,IAAI,KAAK,IAAI,IAAI,EAAE;QACjB,OAAO;YACL,OAAO,EAAE,KAAK;YACd,GAAG,EAAE,IAAI,KAAK,CAAC,6CAA6C,CAAC;SAC9D,CAAC;KACH;IAED,IAAI,IAAI,IAAI,IAAI,EAAE;QAChB,OAAO;YACL,OAAO,EAAE,KAAK;YACd,GAAG,EAAE,IAAI,KAAK,CAAC,4CAA4C,CAAC;SAC7D,CAAC;KACH;IAED,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,EAAE,QAAQ,IAAI,EAAE,CAAC;IAChD,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,EAAE,aAAa,IAAI,EAAE,CAAC;IACrD,MAAM,KAAK,GAAG,KAAK,CAAC,iBAAiB,EAAE,KAAK,IAAI,EAAE,CAAC;IACnD,MAAM,YAAY,GAAG,IAAI,GAAG,CAC1B,IAAI,CAAC,oBAAoB,IAAI,EAAE,CAChC,CAAC;IACF,MAAM,IAAI,GAAG,KAAK,CAAC,QAAQ,EAAE,IAAI,IAAI,EAAE,CAAC;IACxC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,GAAG,IAAA,sCAAgB,EAAC,KAAK,CAAC,CAAC;IAErE,IAAI,KAAK,CAAC,MAAM,IAAI,IAAI,EAAE;QACxB,OAAO;YACL,OAAO,EAAE,KAAK;YACd,GAAG,EAAE,IAAI,KAAK,CAAC,mCAAmC,CAAC;SACpD,CAAC;KACH;IAED,MAAM,EAAE,GAAU;QAChB,cAAc,EAAE,KAAK,CAAC,mBAAmB;QACzC,EAAE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Ae,GAAG,WAAW,CAAC;oBACpC,MAAM;iBACP;aACF;SACF;QAED,IAAI,KAAK,CAAC,YAAY,IAAI,KAAK,CAAC,cAAc,KAAK,KAAK,CAAC,EAAE,EAAE;YAC3D,KAAK,MAAM,UAAU,IAAI,MAAM,EAAE;gBAC/B,IAAI,UAAU,CAAC,YAAY,IAAI,UAAU,CAAC,EAAE,KAAK,KAAK,CAAC,EAAE,EAAE;oBACzD,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;iBAC/B;aACF;YAED,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;gBAC7B,KAAK,CAAC,YAAY,GAAG,KAAK,CAAC;aAC5B;SACF;KACF;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AApED,8DAoEC"}
|
package/dist/trends.js
CHANGED
|
@@ -1,50 +1,39 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.getTrends = void 0;
|
|
13
4
|
const api_1 = require("./api");
|
|
14
|
-
function getTrends(auth) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
5
|
+
async function getTrends(auth) {
|
|
6
|
+
const params = new URLSearchParams();
|
|
7
|
+
(0, api_1.addApiParams)(params, false);
|
|
8
|
+
params.set('count', '20');
|
|
9
|
+
params.set('candidate_source', 'trends');
|
|
10
|
+
params.set('include_page_configuration', 'false');
|
|
11
|
+
params.set('entity_tokens', 'false');
|
|
12
|
+
const res = await (0, api_1.requestApi)(`https://api.twitter.com/2/guide.json?${params.toString()}`, auth);
|
|
13
|
+
if (!res.success) {
|
|
14
|
+
throw res.err;
|
|
15
|
+
}
|
|
16
|
+
const instructions = res.value.timeline?.instructions ?? [];
|
|
17
|
+
if (instructions.length < 2) {
|
|
18
|
+
throw new Error('No trend entries found.');
|
|
19
|
+
}
|
|
20
|
+
// Some of this is silly, but for now we're assuming we know nothing about the
|
|
21
|
+
// data, and that anything can be missing. Go has non-nilable strings and empty
|
|
22
|
+
// slices are nil, so it largely doesn't need to worry about this.
|
|
23
|
+
const entries = instructions[1].addEntries?.entries ?? [];
|
|
24
|
+
if (entries.length < 2) {
|
|
25
|
+
throw new Error('No trend entries found.');
|
|
26
|
+
}
|
|
27
|
+
const items = entries[1].content?.timelineModule?.items ?? [];
|
|
28
|
+
const trends = [];
|
|
29
|
+
for (const item of items) {
|
|
30
|
+
const trend = item.item?.clientEventInfo?.details?.guideDetails?.transparentGuideDetails
|
|
31
|
+
?.trendMetadata?.trendName;
|
|
32
|
+
if (trend != null) {
|
|
33
|
+
trends.push(trend);
|
|
26
34
|
}
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
});
|
|
35
|
+
}
|
|
36
|
+
return trends;
|
|
48
37
|
}
|
|
49
38
|
exports.getTrends = getTrends;
|
|
50
39
|
//# sourceMappingURL=trends.js.map
|
package/dist/trends.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trends.js","sourceRoot":"","sources":["../src/trends.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"trends.js","sourceRoot":"","sources":["../src/trends.ts"],"names":[],"mappings":";;;AAAA,+BAAiD;AAI1C,KAAK,UAAU,SAAS,CAAC,IAAiB;IAC/C,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;IACrC,IAAA,kBAAY,EAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAE5B,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAC1B,MAAM,CAAC,GAAG,CAAC,kBAAkB,EAAE,QAAQ,CAAC,CAAC;IACzC,MAAM,CAAC,GAAG,CAAC,4BAA4B,EAAE,OAAO,CAAC,CAAC;IAClD,MAAM,CAAC,GAAG,CAAC,eA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';
|
|
2
|
+
import { QueryTweetsResponse } from './timeline-v1';
|
|
3
3
|
export interface Mention {
|
|
4
4
|
id: string;
|
|
5
5
|
username?: string;
|
|
@@ -30,14 +30,17 @@ export interface PlaceRaw {
|
|
|
30
30
|
* A parsed Tweet object.
|
|
31
31
|
*/
|
|
32
32
|
export interface Tweet {
|
|
33
|
+
conversationId?: string;
|
|
33
34
|
hashtags: string[];
|
|
34
35
|
html?: string;
|
|
35
36
|
id?: string;
|
|
36
37
|
inReplyToStatus?: Tweet;
|
|
38
|
+
inReplyToStatusId?: string;
|
|
37
39
|
isQuoted?: boolean;
|
|
38
40
|
isPin?: boolean;
|
|
39
41
|
isReply?: boolean;
|
|
40
42
|
isRetweet?: boolean;
|
|
43
|
+
isSelfThread?: boolean;
|
|
41
44
|
likes?: number;
|
|
42
45
|
name?: string;
|
|
43
46
|
mentions: Mention[];
|
|
@@ -45,10 +48,13 @@ export interface Tweet {
|
|
|
45
48
|
photos: Photo[];
|
|
46
49
|
place?: PlaceRaw;
|
|
47
50
|
quotedStatus?: Tweet;
|
|
51
|
+
quotedStatusId?: string;
|
|
48
52
|
replies?: number;
|
|
49
53
|
retweets?: number;
|
|
50
54
|
retweetedStatus?: Tweet;
|
|
55
|
+
retweetedStatusId?: string;
|
|
51
56
|
text?: string;
|
|
57
|
+
thread: Tweet[];
|
|
52
58
|
timeParsed?: Date;
|
|
53
59
|
timestamp?: number;
|
|
54
60
|
urls: string[];
|
|
@@ -58,9 +64,9 @@ export interface Tweet {
|
|
|
58
64
|
views?: number;
|
|
59
65
|
sensitiveContent?: boolean;
|
|
60
66
|
}
|
|
61
|
-
export declare function fetchTweets(userId: string, maxTweets: number,
|
|
62
|
-
export declare function getTweets(user: string, maxTweets: number,
|
|
63
|
-
export declare function getTweetsByUserId(userId: string, maxTweets: number,
|
|
64
|
-
export declare function getLatestTweet(user: string,
|
|
65
|
-
export declare function getTweet(id: string,
|
|
67
|
+
export declare function fetchTweets(userId: string, maxTweets: number, cursor: string | undefined, auth: TwitterAuth): Promise<QueryTweetsResponse>;
|
|
68
|
+
export declare function getTweets(user: string, maxTweets: number, auth: TwitterAuth): AsyncGenerator<Tweet, void>;
|
|
69
|
+
export declare function getTweetsByUserId(userId: string, maxTweets: number, auth: TwitterAuth): AsyncGenerator<Tweet, void>;
|
|
70
|
+
export declare function getLatestTweet(user: string, includeRetweets: boolean, auth: TwitterAuth): Promise<Tweet | null | void>;
|
|
71
|
+
export declare function getTweet(id: string, auth: TwitterAuth): Promise<Tweet | null>;
|
|
66
72
|
//# sourceMappingURL=tweets.d.ts.map
|
package/dist/tweets.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tweets.d.ts","sourceRoot":"","sources":["../src/tweets.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,
|
|
1
|
+
{"version":3,"file":"tweets.d.ts","sourceRoot":"","sources":["../src/tweets.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAUpD,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,KAAK;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,KAAK;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,QAAQ;IACvB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC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,EAAE,MAAM,EAAE,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,wBAAsB,WAAW,CAC/B,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,IAAI,EAAE,WAAW,GAChB,OAAO,CAAC,mBAAmB,CAAC,CAwC9B;AAED,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,WAAW,GAChB,cAAc,CAAC,KAAK,EAAE,IAAI,CAAC,CAW7B;AAED,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,WAAW,GAChB,cAAc,CAAC,KAAK,EAAE,IAAI,CAAC,CAI7B;AAED,wBAAsB,cAAc,CAClC,IAAI,EAAE,MAAM,EACZ,eAAe,EAAE,OAAO,EACxB,IAAI,EAAE,WAAW,GAChB,OAAO,CAAC,KAAK,GAAG,IAAI,GAAG,IAAI,CAAC,CAe9B;AAED,wBAAsB,QAAQ,CAC5B,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,WAAW,GAChB,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CAsCvB"}
|
package/dist/tweets.js
CHANGED
|
@@ -1,113 +1,106 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
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
|
-
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
12
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
13
|
-
var m = o[Symbol.asyncIterator], i;
|
|
14
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
15
|
-
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
16
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
17
4
|
};
|
|
18
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
6
|
exports.getTweet = exports.getLatestTweet = exports.getTweetsByUserId = exports.getTweets = exports.fetchTweets = void 0;
|
|
20
7
|
const api_1 = require("./api");
|
|
21
8
|
const profile_1 = require("./profile");
|
|
22
|
-
const
|
|
9
|
+
const timeline_v2_1 = require("./timeline-v2");
|
|
23
10
|
const timeline_async_1 = require("./timeline-async");
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
11
|
+
const json_stable_stringify_1 = __importDefault(require("json-stable-stringify"));
|
|
12
|
+
async function fetchTweets(userId, maxTweets, cursor, auth) {
|
|
13
|
+
if (maxTweets > 200) {
|
|
14
|
+
maxTweets = 200;
|
|
15
|
+
}
|
|
16
|
+
const variables = {
|
|
17
|
+
userId,
|
|
18
|
+
count: maxTweets,
|
|
19
|
+
includePromotedContent: false,
|
|
20
|
+
withQuickPromoteEligibilityTweetFields: false,
|
|
21
|
+
withVoice: true,
|
|
22
|
+
withV2Timeline: true,
|
|
23
|
+
};
|
|
24
|
+
const features = (0, api_1.addApiFeatures)({
|
|
25
|
+
interactive_text_enabled: true,
|
|
26
|
+
longform_notetweets_inline_media_enabled: false,
|
|
27
|
+
responsive_web_text_conversations_enabled: false,
|
|
28
|
+
tweet_with_visibility_results_prefer_gql_limited_actions_policy_enabled: false,
|
|
29
|
+
vibe_api_enabled: true,
|
|
41
30
|
});
|
|
31
|
+
if (cursor != null && cursor != '') {
|
|
32
|
+
variables['cursor'] = cursor;
|
|
33
|
+
}
|
|
34
|
+
const params = new URLSearchParams();
|
|
35
|
+
params.set('variables', (0, json_stable_stringify_1.default)(variables));
|
|
36
|
+
params.set('features', (0, json_stable_stringify_1.default)(features));
|
|
37
|
+
const res = await (0, api_1.requestApi)(`https://twitter.com/i/api/graphql/UGi7tjRPr-d_U3bCPIko5Q/UserTweets?${params.toString()}`, auth);
|
|
38
|
+
if (!res.success) {
|
|
39
|
+
throw res.err;
|
|
40
|
+
}
|
|
41
|
+
return (0, timeline_v2_1.parseTimelineTweetsV2)(res.value);
|
|
42
42
|
}
|
|
43
43
|
exports.fetchTweets = fetchTweets;
|
|
44
|
-
function getTweets(user, maxTweets,
|
|
45
|
-
return (0, timeline_async_1.getTweetTimeline)(user, maxTweets, (q, mt, c) =>
|
|
46
|
-
const userIdRes =
|
|
44
|
+
function getTweets(user, maxTweets, auth) {
|
|
45
|
+
return (0, timeline_async_1.getTweetTimeline)(user, maxTweets, async (q, mt, c) => {
|
|
46
|
+
const userIdRes = await (0, profile_1.getUserIdByScreenName)(q, auth);
|
|
47
47
|
if (!userIdRes.success) {
|
|
48
48
|
throw userIdRes.err;
|
|
49
49
|
}
|
|
50
50
|
const { value: userId } = userIdRes;
|
|
51
|
-
return fetchTweets(userId, mt,
|
|
52
|
-
})
|
|
51
|
+
return fetchTweets(userId, mt, c, auth);
|
|
52
|
+
});
|
|
53
53
|
}
|
|
54
54
|
exports.getTweets = getTweets;
|
|
55
|
-
function getTweetsByUserId(userId, maxTweets,
|
|
55
|
+
function getTweetsByUserId(userId, maxTweets, auth) {
|
|
56
56
|
return (0, timeline_async_1.getTweetTimeline)(userId, maxTweets, (q, mt, c) => {
|
|
57
|
-
return fetchTweets(q, mt,
|
|
57
|
+
return fetchTweets(q, mt, c, auth);
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
60
|
exports.getTweetsByUserId = getTweetsByUserId;
|
|
61
|
-
function getLatestTweet(user,
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
61
|
+
async function getLatestTweet(user, includeRetweets, auth) {
|
|
62
|
+
const max = includeRetweets ? 1 : 200;
|
|
63
|
+
const timeline = getTweets(user, max, auth);
|
|
64
|
+
if (max == 1) {
|
|
65
|
+
return (await timeline.next()).value;
|
|
66
|
+
}
|
|
67
|
+
for await (const tweet of timeline) {
|
|
68
|
+
if (!tweet.isRetweet) {
|
|
69
|
+
return tweet;
|
|
68
70
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
_c = timeline_2_1.value;
|
|
72
|
-
_d = false;
|
|
73
|
-
try {
|
|
74
|
-
const tweet = _c;
|
|
75
|
-
if (!tweet.isRetweet) {
|
|
76
|
-
return tweet;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
finally {
|
|
80
|
-
_d = true;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
85
|
-
finally {
|
|
86
|
-
try {
|
|
87
|
-
if (!_d && !_a && (_b = timeline_2.return)) yield _b.call(timeline_2);
|
|
88
|
-
}
|
|
89
|
-
finally { if (e_1) throw e_1.error; }
|
|
90
|
-
}
|
|
91
|
-
return null;
|
|
92
|
-
});
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
93
73
|
}
|
|
94
74
|
exports.getLatestTweet = getLatestTweet;
|
|
95
|
-
function getTweet(id,
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return null;
|
|
75
|
+
async function getTweet(id, auth) {
|
|
76
|
+
const variables = {
|
|
77
|
+
focalTweetId: id,
|
|
78
|
+
with_rux_injections: false,
|
|
79
|
+
includePromotedContent: true,
|
|
80
|
+
withCommunity: true,
|
|
81
|
+
withQuickPromoteEligibilityTweetFields: true,
|
|
82
|
+
withBirdwatchNotes: true,
|
|
83
|
+
withVoice: true,
|
|
84
|
+
withV2Timeline: true,
|
|
85
|
+
};
|
|
86
|
+
const features = (0, api_1.addApiFeatures)({
|
|
87
|
+
longform_notetweets_inline_media_enabled: true,
|
|
88
|
+
tweet_with_visibility_results_prefer_gql_limited_actions_policy_enabled: false,
|
|
110
89
|
});
|
|
90
|
+
const params = new URLSearchParams();
|
|
91
|
+
params.set('features', (0, json_stable_stringify_1.default)(features));
|
|
92
|
+
params.set('variables', (0, json_stable_stringify_1.default)(variables));
|
|
93
|
+
const res = await (0, api_1.requestApi)(`https://twitter.com/i/api/graphql/VWFGPVAGkZMGRKGe3GFFnA/TweetDetail?${params.toString()}`, auth);
|
|
94
|
+
if (!res.success) {
|
|
95
|
+
throw res.err;
|
|
96
|
+
}
|
|
97
|
+
const tweets = (0, timeline_v2_1.parseThreadedConversation)(res.value);
|
|
98
|
+
for (const tweet of tweets) {
|
|
99
|
+
if (tweet.id === id) {
|
|
100
|
+
return tweet;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
111
104
|
}
|
|
112
105
|
exports.getTweet = getTweet;
|
|
113
106
|
//# sourceMappingURL=tweets.js.map
|
package/dist/tweets.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tweets.js","sourceRoot":"","sources":["../src/tweets.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tweets.js","sourceRoot":"","sources":["../src/tweets.ts"],"names":[],"mappings":";;;;;;AAAA,+BAAmD;AAEnD,uCAAkD;AAElD,+CAKuB;AACvB,qDAAoD;AACpD,kFAA8C;AAuEvC,KAAK,UAAU,WAAW,CAC/B,MAAc,EACd,SAAiB,EACjB,MAA0B,EAC1B,IAAiB;IAEjB,IAAI,SAAS,GAAG,GAAG,EAAE;QACnB,SAAS,GAAG,GAAG,CAAC;KACjB;IAED,MAAM,SAAS,GAAwB;QACrC,MAAM;QACN,KAAK,EAAE,SAAS;QAChB,sBAAsB,EAAE,KAAK;QAC7B,sCAAsC,EAAE,KAAK;QAC7C,SAAS,EAAE,IAAI;QACf,cAAc,EAAE,IAAI;KACrB,CAAC;IAEF,MAAM,QAAQ,GAAG,IAAA,oBAAc,EAAC;QAC9B,wBAAwB,EAAE,IAAI;QAC9B,wCAAwC,EAAE,KAAK;QAC/C,yCAAyC,EAAE,KAAK;QAChD,uEAAuE,EACrE,KAAK;QACP,gBAAgB,EAAE,IAAI;KACvB,CAAC,CAAC;IAEH,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,IAAI,EAAE,EAAE;QAClC,SAAS,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC;KAC9B;IAED,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;IACrC,MAAM,CAAC,GAAG,CAAC,WAAW,EAAE,IAAA,+BAAS,EAAC,SAAS,CAAC,CAAC,CAAC;IAC9C,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,IAAA,+BAAS,EAAC,QAAQ,CAAC,CAAC,CAAC;IAE5C,MAAM,GAAG,GAAG,MAAM,IAAA,gB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AC,KAAK,CAAC,CAAC;IACpD,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;QAC1B,IAAI,KAAK,CAAC,EAAE,KAAK,EAAE,EAAE;YACnB,OAAO,KAAK,CAAC;SACd;KACF;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAzCD,4BAyCC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type NonNullableField<T, K extends keyof T> = {
|
|
2
|
+
[P in K]-?: T[P];
|
|
3
|
+
} & T;
|
|
4
|
+
export declare function isFieldDefined<T, K extends keyof T>(key: K): (value: T) => value is NonNullableField<T, K>;
|
|
5
|
+
export declare function isDefined<T>(value: T | null | undefined): value is T;
|
|
6
|
+
//# sourceMappingURL=type-util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-util.d.ts","sourceRoot":"","sources":["../src/type-util.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI;KAClD,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACjB,GAAG,CAAC,CAAC;AAEN,wBAAgB,cAAc,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,WACjC,CAAC,qCAG1B;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,GAAG,KAAK,IAAI,CAAC,CAEpE"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isDefined = exports.isFieldDefined = void 0;
|
|
4
|
+
function isFieldDefined(key) {
|
|
5
|
+
return function (value) {
|
|
6
|
+
return isDefined(value[key]);
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
exports.isFieldDefined = isFieldDefined;
|
|
10
|
+
function isDefined(value) {
|
|
11
|
+
return value != null;
|
|
12
|
+
}
|
|
13
|
+
exports.isDefined = isDefined;
|
|
14
|
+
//# sourceMappingURL=type-util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-util.js","sourceRoot":"","sources":["../src/type-util.ts"],"names":[],"mappings":";;;AAIA,SAAgB,cAAc,CAAuB,GAAM;IACzD,OAAO,UAAU,KAAQ;QACvB,OAAO,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/B,CAAC,CAAC;AACJ,CAAC;AAJD,wCAIC;AAED,SAAgB,SAAS,CAAI,KAA2B;IACtD,OAAO,KAAK,IAAI,IAAI,CAAC;AACvB,CAAC;AAFD,8BAEC"}
|