@the-convocation/twitter-scraper 0.1.5 → 0.2.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/api.d.ts +1 -3
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +38 -44
- 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 +167 -179
- 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.js +29 -52
- package/dist/scraper.js.map +1 -1
- package/dist/search.js +46 -61
- package/dist/search.js.map +1 -1
- package/dist/timeline-async.js +34 -50
- package/dist/timeline-async.js.map +1 -1
- package/dist/timeline.js +33 -38
- package/dist/timeline.js.map +1 -1
- package/dist/trends.js +31 -42
- package/dist/trends.js.map +1 -1
- package/dist/tweets.js +43 -83
- package/dist/tweets.js.map +1 -1
- package/package.json +9 -2
package/dist/search.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
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.fetchSearchProfiles = exports.fetchSearchTweets = exports.searchProfiles = exports.searchTweets = exports.SearchMode = void 0;
|
|
13
4
|
const api_1 = require("./api");
|
|
@@ -36,61 +27,55 @@ function searchProfiles(query, maxProfiles, auth) {
|
|
|
36
27
|
});
|
|
37
28
|
}
|
|
38
29
|
exports.searchProfiles = searchProfiles;
|
|
39
|
-
function fetchSearchTweets(query, maxTweets, includeReplies, searchMode, auth, cursor) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return (0, timeline_1.parseTweets)(timeline);
|
|
43
|
-
});
|
|
30
|
+
async function fetchSearchTweets(query, maxTweets, includeReplies, searchMode, auth, cursor) {
|
|
31
|
+
const timeline = await getSearchTimeline(query, maxTweets, includeReplies, searchMode, auth, cursor);
|
|
32
|
+
return (0, timeline_1.parseTweets)(timeline);
|
|
44
33
|
}
|
|
45
34
|
exports.fetchSearchTweets = fetchSearchTweets;
|
|
46
|
-
function fetchSearchProfiles(query, maxProfiles, auth, cursor) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return (0, timeline_1.parseUsers)(timeline);
|
|
50
|
-
});
|
|
35
|
+
async function fetchSearchProfiles(query, maxProfiles, auth, cursor) {
|
|
36
|
+
const timeline = await getSearchTimeline(query, maxProfiles, false, SearchMode.Users, auth, cursor);
|
|
37
|
+
return (0, timeline_1.parseUsers)(timeline);
|
|
51
38
|
}
|
|
52
39
|
exports.fetchSearchProfiles = fetchSearchProfiles;
|
|
53
|
-
function getSearchTimeline(query, maxItems, includeReplies, searchMode, auth, cursor) {
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
return res.value;
|
|
94
|
-
});
|
|
40
|
+
async function getSearchTimeline(query, maxItems, includeReplies, searchMode, auth, cursor) {
|
|
41
|
+
if (!auth.isLoggedIn()) {
|
|
42
|
+
throw new Error('Scraper is not logged-in for search.');
|
|
43
|
+
}
|
|
44
|
+
if (maxItems > 50) {
|
|
45
|
+
maxItems = 50;
|
|
46
|
+
}
|
|
47
|
+
const params = new URLSearchParams();
|
|
48
|
+
(0, api_1.addApiParams)(params, includeReplies);
|
|
49
|
+
params.set('q', query);
|
|
50
|
+
params.set('count', `${maxItems}`);
|
|
51
|
+
params.set('query_source', 'typed_query');
|
|
52
|
+
params.set('pc', '1');
|
|
53
|
+
params.set('requestContext', 'launch');
|
|
54
|
+
params.set('spelling_corrections', '1');
|
|
55
|
+
params.set('include_ext_edit_control', 'true');
|
|
56
|
+
if (cursor != null && cursor != '') {
|
|
57
|
+
params.set('cursor', cursor);
|
|
58
|
+
}
|
|
59
|
+
switch (searchMode) {
|
|
60
|
+
case SearchMode.Latest:
|
|
61
|
+
params.set('tweet_search_mode', 'live');
|
|
62
|
+
break;
|
|
63
|
+
case SearchMode.Photos:
|
|
64
|
+
params.set('result_filter', 'image');
|
|
65
|
+
break;
|
|
66
|
+
case SearchMode.Videos:
|
|
67
|
+
params.set('result_filter', 'video');
|
|
68
|
+
break;
|
|
69
|
+
case SearchMode.Users:
|
|
70
|
+
params.set('result_filter', 'user');
|
|
71
|
+
break;
|
|
72
|
+
default:
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
const res = await (0, api_1.requestApi)(`https://twitter.com/i/api/2/search/adaptive.json?${params.toString()}`, auth);
|
|
76
|
+
if (!res.success) {
|
|
77
|
+
throw res.err;
|
|
78
|
+
}
|
|
79
|
+
return res.value;
|
|
95
80
|
}
|
|
96
81
|
//# sourceMappingURL=search.js.map
|
package/dist/search.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.js","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"search.js","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":";;;AAAA,+BAAiD;AAGjD,yCAMoB;AACpB,qDAAqE;AAGrE;;GAEG;AACH,IAAY,UAMX;AAND,WAAY,UAAU;IACpB,yCAAG,CAAA;IACH,+CAAM,CAAA;IACN,+CAAM,CAAA;IACN,+CAAM,CAAA;IACN,6CAAK,CAAA;AACP,CAAC,EANW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAMrB;AAED,SAAgB,YAAY,CAC1B,KAAa,EACb,SAAiB,EACjB,cAAuB,EACvB,UAAsB,EACtB,IAAiB;IAEjB,OAAO,IAAA,iCAAgB,EAAC,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE;QACrD,OAAO,iBAAiB,CAAC,CAAC,EAAE,EAAE,EAAE,cAAc,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IACvE,CAAC,CAAC,CAAC;AACL,CAAC;AAVD,oCAUC;AAED,SAAgB,cAAc,CAC5B,KAAa,EACb,WAAmB,EACnB,IAAiB;IAEjB,OAAO,IAAA,gCAAe,EAAC,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE;QACtD,OAAO,mBAAmB,CA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AAC,cAAc,EAAE,aAAa,CAAC,CAAC;IAC1C,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACtB,MAAM,CAAC,GAAG,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAC;IACvC,MAAM,CAAC,GAAG,CAAC,sBAAsB,EAAE,GAAG,CAAC,CAAC;IACxC,MAAM,CAAC,GAAG,CAAC,0BAA0B,EAAE,MAAM,CAAC,CAAC;IAC/C,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,IAAI,EAAE,EAAE;QAClC,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;KAC9B;IAED,QAAQ,UAAU,EAAE;QAClB,KAAK,UAAU,CAAC,MAAM;YACpB,MAAM,CAAC,GAAG,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAAC;YACxC,MAAM;QACR,KAAK,UAAU,CAAC,MAAM;YACpB,MAAM,CAAC,GAAG,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;YACrC,MAAM;QACR,KAAK,UAAU,CAAC,MAAM;YACpB,MAAM,CAAC,GAAG,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;YACrC,MAAM;QACR,KAAK,UAAU,CAAC,KAAK;YACnB,MAAM,CAAC,GAAG,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;YACpC,MAAM;QACR;YACE,MAAM;KACT;IAED,MAAM,GAAG,GAAG,MAAM,IAAA,gBAAU,EAC1B,oDAAoD,MAAM,CAAC,QAAQ,EAAE,EAAE,EACvE,IAAI,CACL,CAAC;IACF,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE;QAChB,MAAM,GAAG,CAAC,GAAG,CAAC;KACf;IAED,OAAO,GAAG,CAAC,KAAK,CAAC;AACnB,CAAC"}
|
package/dist/timeline-async.js
CHANGED
|
@@ -1,64 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
3
|
-
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
4
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
5
|
-
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
6
|
-
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
7
|
-
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
|
8
|
-
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
9
|
-
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
10
|
-
function fulfill(value) { resume("next", value); }
|
|
11
|
-
function reject(value) { resume("throw", value); }
|
|
12
|
-
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
13
|
-
};
|
|
14
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
3
|
exports.getTweetTimeline = exports.getUserTimeline = void 0;
|
|
16
|
-
function getUserTimeline(query, maxProfiles, fetchFunc) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
4
|
+
async function* getUserTimeline(query, maxProfiles, fetchFunc) {
|
|
5
|
+
let nProfiles = 0;
|
|
6
|
+
let cursor = undefined;
|
|
7
|
+
while (nProfiles < maxProfiles) {
|
|
8
|
+
const batch = await fetchFunc(query, maxProfiles, cursor);
|
|
9
|
+
const { profiles, next } = batch;
|
|
10
|
+
if (profiles.length === 0) {
|
|
11
|
+
break;
|
|
12
|
+
}
|
|
13
|
+
for (const profile of profiles) {
|
|
14
|
+
if (nProfiles < maxProfiles) {
|
|
15
|
+
cursor = next;
|
|
16
|
+
yield profile;
|
|
25
17
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
cursor = next;
|
|
29
|
-
yield yield __await(profile);
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
nProfiles++;
|
|
18
|
+
else {
|
|
19
|
+
break;
|
|
35
20
|
}
|
|
21
|
+
nProfiles++;
|
|
36
22
|
}
|
|
37
|
-
}
|
|
23
|
+
}
|
|
38
24
|
}
|
|
39
25
|
exports.getUserTimeline = getUserTimeline;
|
|
40
|
-
function getTweetTimeline(query, maxTweets, fetchFunc) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
26
|
+
async function* getTweetTimeline(query, maxTweets, fetchFunc) {
|
|
27
|
+
let nTweets = 0;
|
|
28
|
+
let cursor = undefined;
|
|
29
|
+
while (nTweets < maxTweets) {
|
|
30
|
+
const batch = await fetchFunc(query, maxTweets, cursor);
|
|
31
|
+
const { tweets, next } = batch;
|
|
32
|
+
if (tweets.length === 0) {
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
for (const tweet of tweets) {
|
|
36
|
+
if (nTweets < maxTweets) {
|
|
37
|
+
cursor = next;
|
|
38
|
+
yield tweet;
|
|
49
39
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
cursor = next;
|
|
53
|
-
yield yield __await(tweet);
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
nTweets++;
|
|
40
|
+
else {
|
|
41
|
+
break;
|
|
59
42
|
}
|
|
43
|
+
nTweets++;
|
|
60
44
|
}
|
|
61
|
-
}
|
|
45
|
+
}
|
|
62
46
|
}
|
|
63
47
|
exports.getTweetTimeline = getTweetTimeline;
|
|
64
48
|
//# sourceMappingURL=timeline-async.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeline-async.js","sourceRoot":"","sources":["../src/timeline-async.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"timeline-async.js","sourceRoot":"","sources":["../src/timeline-async.ts"],"names":[],"mappings":";;;AAyBO,KAAK,SAAS,CAAC,CAAC,eAAe,CACpC,KAAa,EACb,WAAmB,EACnB,SAAwB;IAExB,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,IAAI,MAAM,GAAuB,SAAS,CAAC;IAC3C,OAAO,SAAS,GAAG,WAAW,EAAE;QAC9B,MAAM,KAAK,GAA0B,MAAM,SAAS,CAClD,KAAK,EACL,WAAW,EACX,MAAM,CACP,CAAC;QAEF,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;QAEjC,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;YACzB,MAAM;SACP;QAED,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;YAC9B,IAAI,SAAS,GAAG,WAAW,EAAE;gBAC3B,MAAM,GAAG,IAAI,CAAC;gBACd,MAAM,OAAO,CAAC;aACf;iBAAM;gBACL,MAAM;aACP;YAED,SAAS,EAAE,CAAC;SACb;KACF;AACH,CAAC;AA/BD,0CA+BC;AAEM,KAAK,SAAS,CAAC,CAAC,gBAAgB,CACrC,KAAa,EACb,SAAiB,EACjB,SAAsB;IAEtB,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,IAAI,MAAM,GAAuB,SAAS,CAAC;IAC3C,OAAO,OAAO,GAAG,SAAS,EAAE;QAC1B,MAAM,KAAK,GAAwB,MAAM,SAAS,CAChD,KAAK,EACL,SAAS,EACT,MAAM,CACP,CAAC;QAEF,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;QAE/B,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;YACvB,MAAM;SACP;QAED,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;YAC1B,IAAI,OAAO,GAAG,SAAS,EAAE;gBACvB,MAAM,GAAG,IAAI,CAAC;gBACd,MAAM,KAAK,CAAC;aACb;iBAAM;gBACL,MAAM;aACP;YAED,OAAO,EAAE,CAAC;SACX;KACF;AACH,CAAC;AA/BD,4CA+BC"}
|
package/dist/timeline.js
CHANGED
|
@@ -14,28 +14,27 @@ function isDefined(value) {
|
|
|
14
14
|
return value != null;
|
|
15
15
|
}
|
|
16
16
|
function parseTweet(timeline, id) {
|
|
17
|
-
|
|
18
|
-
const tweets = (_b = (_a = timeline.globalObjects) === null || _a === void 0 ? void 0 : _a.tweets) !== null && _b !== void 0 ? _b : {};
|
|
17
|
+
const tweets = timeline.globalObjects?.tweets ?? {};
|
|
19
18
|
const tweet = tweets[id];
|
|
20
|
-
if (
|
|
19
|
+
if (tweet?.user_id_str == null) {
|
|
21
20
|
return {
|
|
22
21
|
success: false,
|
|
23
22
|
err: new Error(`Tweet "${id}" was not found in the timeline object.`),
|
|
24
23
|
};
|
|
25
24
|
}
|
|
26
|
-
const users =
|
|
25
|
+
const users = timeline.globalObjects?.users ?? {};
|
|
27
26
|
const user = users[tweet.user_id_str];
|
|
28
|
-
if (
|
|
27
|
+
if (user?.screen_name == null) {
|
|
29
28
|
return {
|
|
30
29
|
success: false,
|
|
31
30
|
err: new Error(`User "${tweet.user_id_str}" has no username data.`),
|
|
32
31
|
};
|
|
33
32
|
}
|
|
34
|
-
const hashtags =
|
|
35
|
-
const mentions =
|
|
36
|
-
const media =
|
|
37
|
-
const pinnedTweets = new Set(
|
|
38
|
-
const urls =
|
|
33
|
+
const hashtags = tweet.entities?.hashtags ?? [];
|
|
34
|
+
const mentions = tweet.entities?.user_mentions ?? [];
|
|
35
|
+
const media = tweet.extended_entities?.media ?? [];
|
|
36
|
+
const pinnedTweets = new Set(user.pinned_tweet_ids_str ?? []);
|
|
37
|
+
const urls = tweet.entities?.urls ?? [];
|
|
39
38
|
const { photos, videos, sensitiveContent } = parseMediaGroups(media);
|
|
40
39
|
const tw = {
|
|
41
40
|
id,
|
|
@@ -65,7 +64,7 @@ function parseTweet(timeline, id) {
|
|
|
65
64
|
tw.timeParsed = new Date(Date.parse(tweet.created_at));
|
|
66
65
|
tw.timestamp = Math.floor(tw.timeParsed.valueOf() / 1000);
|
|
67
66
|
}
|
|
68
|
-
if (
|
|
67
|
+
if (tweet.place?.id != null) {
|
|
69
68
|
tw.place = tweet.place;
|
|
70
69
|
}
|
|
71
70
|
if (tweet.quoted_status_id_str != null) {
|
|
@@ -89,7 +88,7 @@ function parseTweet(timeline, id) {
|
|
|
89
88
|
tw.retweetedStatus = retweetedStatusResult.tweet;
|
|
90
89
|
}
|
|
91
90
|
}
|
|
92
|
-
const views = parseInt(
|
|
91
|
+
const views = parseInt(tweet.ext_views?.count ?? '');
|
|
93
92
|
if (!isNaN(views)) {
|
|
94
93
|
tw.views = views;
|
|
95
94
|
}
|
|
@@ -102,7 +101,7 @@ function parseTweet(timeline, id) {
|
|
|
102
101
|
tw.sensitiveContent = true;
|
|
103
102
|
}
|
|
104
103
|
// HTML parsing with regex :)
|
|
105
|
-
let html =
|
|
104
|
+
let html = tweet.full_text ?? '';
|
|
106
105
|
const foundedMedia = [];
|
|
107
106
|
html = html.replace(reHashtag, linkHashtagHtml);
|
|
108
107
|
html = html.replace(reUsername, linkUsernameHtml);
|
|
@@ -151,13 +150,12 @@ function parseMediaGroups(media) {
|
|
|
151
150
|
return { sensitiveContent, photos, videos };
|
|
152
151
|
}
|
|
153
152
|
function parseVideo(m) {
|
|
154
|
-
var _a, _b;
|
|
155
153
|
const video = {
|
|
156
154
|
id: m.id_str,
|
|
157
155
|
preview: m.media_url_https,
|
|
158
156
|
};
|
|
159
157
|
let maxBitrate = 0;
|
|
160
|
-
const variants =
|
|
158
|
+
const variants = m.video_info?.variants ?? [];
|
|
161
159
|
for (const variant of variants) {
|
|
162
160
|
const bitrate = variant.bitrate;
|
|
163
161
|
if (bitrate != null && bitrate > maxBitrate && variant.url != null) {
|
|
@@ -181,13 +179,12 @@ function linkUsernameHtml(username) {
|
|
|
181
179
|
}
|
|
182
180
|
function unwrapTcoUrlHtml(tweet, foundedMedia) {
|
|
183
181
|
return function (tco) {
|
|
184
|
-
|
|
185
|
-
for (const entity of (_b = (_a = tweet.entities) === null || _a === void 0 ? void 0 : _a.urls) !== null && _b !== void 0 ? _b : []) {
|
|
182
|
+
for (const entity of tweet.entities?.urls ?? []) {
|
|
186
183
|
if (tco === entity.url && entity.expanded_url != null) {
|
|
187
184
|
return `<a href="${entity.expanded_url}">${tco}</a>`;
|
|
188
185
|
}
|
|
189
186
|
}
|
|
190
|
-
for (const entity of
|
|
187
|
+
for (const entity of tweet.extended_entities?.media ?? []) {
|
|
191
188
|
if (tco === entity.url && entity.media_url_https != null) {
|
|
192
189
|
foundedMedia.push(entity.media_url_https);
|
|
193
190
|
return `<br><a href="${tco}"><img src="${entity.media_url_https}"/></a>`;
|
|
@@ -197,14 +194,13 @@ function unwrapTcoUrlHtml(tweet, foundedMedia) {
|
|
|
197
194
|
};
|
|
198
195
|
}
|
|
199
196
|
function parseTweets(timeline) {
|
|
200
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
201
197
|
let cursor;
|
|
202
198
|
let pinnedTweet;
|
|
203
199
|
let orderedTweets = [];
|
|
204
|
-
for (const instruction of
|
|
200
|
+
for (const instruction of timeline.timeline?.instructions ?? []) {
|
|
205
201
|
const { pinEntry, addEntries, replaceEntry } = instruction;
|
|
206
202
|
// Handle pin instruction
|
|
207
|
-
const pinnedTweetId =
|
|
203
|
+
const pinnedTweetId = pinEntry?.entry?.content?.item?.content?.tweet?.id;
|
|
208
204
|
if (pinnedTweetId != null) {
|
|
209
205
|
const tweetResult = parseTweet(timeline, pinnedTweetId);
|
|
210
206
|
if (tweetResult.success) {
|
|
@@ -212,22 +208,22 @@ function parseTweets(timeline) {
|
|
|
212
208
|
}
|
|
213
209
|
}
|
|
214
210
|
// Handle add instructions
|
|
215
|
-
for (const { content } of
|
|
216
|
-
const tweetId =
|
|
211
|
+
for (const { content } of addEntries?.entries ?? []) {
|
|
212
|
+
const tweetId = content?.item?.content?.tweet?.id;
|
|
217
213
|
if (tweetId != null) {
|
|
218
214
|
const tweetResult = parseTweet(timeline, tweetId);
|
|
219
215
|
if (tweetResult.success) {
|
|
220
216
|
orderedTweets.push(tweetResult.tweet);
|
|
221
217
|
}
|
|
222
218
|
}
|
|
223
|
-
const operation = content
|
|
224
|
-
if (
|
|
225
|
-
cursor =
|
|
219
|
+
const operation = content?.operation;
|
|
220
|
+
if (operation?.cursor?.cursorType === 'Bottom') {
|
|
221
|
+
cursor = operation?.cursor?.value;
|
|
226
222
|
}
|
|
227
223
|
}
|
|
228
224
|
// Handle replace instruction
|
|
229
|
-
const operation =
|
|
230
|
-
if (
|
|
225
|
+
const operation = replaceEntry?.entry?.content?.operation;
|
|
226
|
+
if (operation?.cursor?.cursorType === 'Bottom') {
|
|
231
227
|
cursor = operation.cursor.value;
|
|
232
228
|
}
|
|
233
229
|
}
|
|
@@ -241,9 +237,8 @@ function parseTweets(timeline) {
|
|
|
241
237
|
}
|
|
242
238
|
exports.parseTweets = parseTweets;
|
|
243
239
|
function parseUsers(timeline) {
|
|
244
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
245
240
|
const users = new Map();
|
|
246
|
-
const userObjects =
|
|
241
|
+
const userObjects = timeline.globalObjects?.users ?? {};
|
|
247
242
|
for (const id in userObjects) {
|
|
248
243
|
const legacy = userObjects[id];
|
|
249
244
|
if (legacy == null) {
|
|
@@ -254,20 +249,20 @@ function parseUsers(timeline) {
|
|
|
254
249
|
}
|
|
255
250
|
let cursor;
|
|
256
251
|
const orderedProfiles = [];
|
|
257
|
-
for (const instruction of
|
|
258
|
-
for (const entry of
|
|
259
|
-
const userId =
|
|
252
|
+
for (const instruction of timeline.timeline?.instructions ?? []) {
|
|
253
|
+
for (const entry of instruction.addEntries?.entries ?? []) {
|
|
254
|
+
const userId = entry.content?.item?.content?.user?.id;
|
|
260
255
|
const profile = users.get(userId);
|
|
261
256
|
if (profile != null) {
|
|
262
257
|
orderedProfiles.push(profile);
|
|
263
258
|
}
|
|
264
|
-
const operation =
|
|
265
|
-
if (
|
|
266
|
-
cursor =
|
|
259
|
+
const operation = entry.content?.operation;
|
|
260
|
+
if (operation?.cursor?.cursorType === 'Bottom') {
|
|
261
|
+
cursor = operation?.cursor?.value;
|
|
267
262
|
}
|
|
268
263
|
}
|
|
269
|
-
const operation =
|
|
270
|
-
if (
|
|
264
|
+
const operation = instruction.replaceEntry?.entry?.content?.operation;
|
|
265
|
+
if (operation?.cursor?.cursorType === 'Bottom') {
|
|
271
266
|
cursor = operation.cursor.value;
|
|
272
267
|
}
|
|
273
268
|
}
|
package/dist/timeline.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeline.js","sourceRoot":"","sources":["../src/timeline.ts"],"names":[],"mappings":";;;AAAA,uCAAiE;AAkKjE,MAAM,SAAS,GAAG,cAAc,CAAC;AACjC,MAAM,YAAY,GAAG,gDAAgD,CAAC;AACtE,MAAM,UAAU,GAAG,mBAAmB,CAAC;AAMvC,SAAS,cAAc,CAAuB,GAAM;IAClD,OAAO,UAAU,KAAQ;QACvB,OAAO,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/B,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,SAAS,CAAI,KAA2B;IAC/C,OAAO,KAAK,IAAI,IAAI,CAAC;AACvB,CAAC;AAMD,SAAgB,UAAU,CACxB,QAAqB,EACrB,EAAU
|
|
1
|
+
{"version":3,"file":"timeline.js","sourceRoot":"","sources":["../src/timeline.ts"],"names":[],"mappings":";;;AAAA,uCAAiE;AAkKjE,MAAM,SAAS,GAAG,cAAc,CAAC;AACjC,MAAM,YAAY,GAAG,gDAAgD,CAAC;AACtE,MAAM,UAAU,GAAG,mBAAmB,CAAC;AAMvC,SAAS,cAAc,CAAuB,GAA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;YACzD,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC;YACtD,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YAClC,IAAI,OAAO,IAAI,IAAI,EAAE;gBACnB,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;aAC/B;YAED,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,EAAE,SAAS,CAAC;YAC3C,IAAI,SAAS,EAAE,MAAM,EAAE,UAAU,KAAK,QAAQ,EAAE;gBAC9C,MAAM,GAAG,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC;aACnC;SACF;QAED,MAAM,SAAS,GAAG,WAAW,CAAC,YAAY,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,CAAC;QACtE,IAAI,SAAS,EAAE,MAAM,EAAE,UAAU,KAAK,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,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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