@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/tweets.js
CHANGED
|
@@ -1,55 +1,37 @@
|
|
|
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
|
-
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); }
|
|
17
|
-
};
|
|
18
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
3
|
exports.getTweet = exports.getLatestTweet = exports.getTweetsByUserId = exports.getTweets = exports.fetchTweets = void 0;
|
|
20
4
|
const api_1 = require("./api");
|
|
21
5
|
const profile_1 = require("./profile");
|
|
22
6
|
const timeline_1 = require("./timeline");
|
|
23
7
|
const timeline_async_1 = require("./timeline-async");
|
|
24
|
-
function fetchTweets(userId, maxTweets, includeReplies, cursor, auth) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return (0, timeline_1.parseTweets)(res.value);
|
|
41
|
-
});
|
|
8
|
+
async function fetchTweets(userId, maxTweets, includeReplies, cursor, auth) {
|
|
9
|
+
if (maxTweets > 200) {
|
|
10
|
+
maxTweets = 200;
|
|
11
|
+
}
|
|
12
|
+
const params = new URLSearchParams();
|
|
13
|
+
(0, api_1.addApiParams)(params, includeReplies);
|
|
14
|
+
params.set('count', `${maxTweets}`);
|
|
15
|
+
params.set('userId', userId);
|
|
16
|
+
if (cursor != null && cursor != '') {
|
|
17
|
+
params.set('cursor', cursor);
|
|
18
|
+
}
|
|
19
|
+
const res = await (0, api_1.requestApi)(`https://api.twitter.com/2/timeline/profile/${userId}.json?${params.toString()}`, auth);
|
|
20
|
+
if (!res.success) {
|
|
21
|
+
throw res.err;
|
|
22
|
+
}
|
|
23
|
+
return (0, timeline_1.parseTweets)(res.value);
|
|
42
24
|
}
|
|
43
25
|
exports.fetchTweets = fetchTweets;
|
|
44
26
|
function getTweets(user, maxTweets, includeReplies, auth) {
|
|
45
|
-
return (0, timeline_async_1.getTweetTimeline)(user, maxTweets, (q, mt, c) =>
|
|
46
|
-
const userIdRes =
|
|
27
|
+
return (0, timeline_async_1.getTweetTimeline)(user, maxTweets, async (q, mt, c) => {
|
|
28
|
+
const userIdRes = await (0, profile_1.getUserIdByScreenName)(q, auth);
|
|
47
29
|
if (!userIdRes.success) {
|
|
48
30
|
throw userIdRes.err;
|
|
49
31
|
}
|
|
50
32
|
const { value: userId } = userIdRes;
|
|
51
33
|
return fetchTweets(userId, mt, includeReplies, c, auth);
|
|
52
|
-
})
|
|
34
|
+
});
|
|
53
35
|
}
|
|
54
36
|
exports.getTweets = getTweets;
|
|
55
37
|
function getTweetsByUserId(userId, maxTweets, includeReplies, auth) {
|
|
@@ -58,56 +40,34 @@ function getTweetsByUserId(userId, maxTweets, includeReplies, auth) {
|
|
|
58
40
|
});
|
|
59
41
|
}
|
|
60
42
|
exports.getTweetsByUserId = getTweetsByUserId;
|
|
61
|
-
function getLatestTweet(user, includeReplies, includeRetweets, auth) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
43
|
+
async function getLatestTweet(user, includeReplies, includeRetweets, auth) {
|
|
44
|
+
const max = includeRetweets ? 1 : 200;
|
|
45
|
+
const timeline = await getTweets(user, max, includeReplies, auth);
|
|
46
|
+
if (max == 1) {
|
|
47
|
+
return (await timeline.next()).value;
|
|
48
|
+
}
|
|
49
|
+
for await (const tweet of timeline) {
|
|
50
|
+
if (!tweet.isRetweet) {
|
|
51
|
+
return tweet;
|
|
68
52
|
}
|
|
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
|
-
});
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
93
55
|
}
|
|
94
56
|
exports.getLatestTweet = getLatestTweet;
|
|
95
|
-
function getTweet(id, includeReplies, auth) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
57
|
+
async function getTweet(id, includeReplies, auth) {
|
|
58
|
+
const params = new URLSearchParams();
|
|
59
|
+
(0, api_1.addApiParams)(params, includeReplies);
|
|
60
|
+
const res = await (0, api_1.requestApi)(`https://twitter.com/i/api/2/timeline/conversation/${id}.json?${params.toString()}`, auth);
|
|
61
|
+
if (!res.success) {
|
|
62
|
+
throw res.err;
|
|
63
|
+
}
|
|
64
|
+
const { tweets } = (0, timeline_1.parseTweets)(res.value);
|
|
65
|
+
for (const tweet of tweets) {
|
|
66
|
+
if (tweet.id === id) {
|
|
67
|
+
return tweet;
|
|
102
68
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
if (tweet.id === id) {
|
|
106
|
-
return tweet;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return null;
|
|
110
|
-
});
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
111
71
|
}
|
|
112
72
|
exports.getTweet = getTweet;
|
|
113
73
|
//# 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,+BAAiD;AAEjD,uCAAkD;AAClD,yCAA2E;AAC3E,qDAAoD;AAiE7C,KAAK,UAAU,WAAW,CAC/B,MAAc,EACd,SAAiB,EACjB,cAAuB,EACvB,MAA0B,EAC1B,IAAiB;IAEjB,IAAI,SAAS,GAAG,GAAG,EAAE;QACnB,SAAS,GAAG,GAAG,CAAC;KACjB;IAED,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;IACrC,IAAA,kBAAY,EAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAErC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,SAAS,EAAE,CAAC,CAAC;IACpC,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC7B,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,IAAI,EAAE,EAAE;QAClC,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;KAC9B;IAED,MAAM,GAAG,GAAG,MAAM,IAAA,gBAAU,EAC1B,8CAA8C,MAAM,SAAS,MAAM,CAAC,QAAQ,EAAE,EAAE,EAChF,IAAI,CACL,CAAC;IACF,IAAI,CAAC,GAAG,CAAC,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,cAAc,EAAE,IAAI,CAAC,CAAC;IAElE,IAAI,GAAG,IAAI,CAAC,EAAE;QACZ,OAAO,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC;KACtC;IAED,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,QAAQ,EAAE;QAClC,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE;YACpB,OAAO,KAAK,CAAC;SACd;KACF;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AApBD,wCAoBC;AAEM,KAAK,UAAU,QAAQ,CAC5B,EAAU,EACV,cAAuB,EACvB,IAAiB;IAEjB,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;IACrC,IAAA,kBAAY,EAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAErC,MAAM,GAAG,GAAG,MAAM,IAAA,gBAAU,EAC1B,qDAAqD,EAAE,SAAS,MAAM,CAAC,QAAQ,EAAE,EAAE,EACnF,IAAI,CACL,CAAC;IACF,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE;QAChB,MAAM,GAAG,CAAC,GAAG,CAAC;KACf;IAED,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,sBAAW,EAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC1C,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;AAxBD,4BAwBC"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@the-convocation/twitter-scraper",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"main": "dist/_module.js",
|
|
5
5
|
"repository": "https://github.com/the-convocation/twitter-scraper.git",
|
|
6
6
|
"author": "karashiiro <49822414+karashiiro@users.noreply.github.com>",
|
|
7
7
|
"license": "MIT",
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">=16"
|
|
10
|
+
},
|
|
8
11
|
"scripts": {
|
|
9
12
|
"build": "tsc",
|
|
10
13
|
"commit": "cz",
|
|
@@ -15,14 +18,18 @@
|
|
|
15
18
|
"test": "jest"
|
|
16
19
|
},
|
|
17
20
|
"dependencies": {
|
|
18
|
-
"
|
|
21
|
+
"cross-fetch": "^4.0.0-alpha.5",
|
|
22
|
+
"headers-polyfill": "^3.1.2",
|
|
23
|
+
"set-cookie-parser": "^2.6.0",
|
|
19
24
|
"tough-cookie": "^4.1.2",
|
|
20
25
|
"tslib": "^2.5.2"
|
|
21
26
|
},
|
|
22
27
|
"devDependencies": {
|
|
23
28
|
"@commitlint/cli": "^17.6.3",
|
|
24
29
|
"@commitlint/config-conventional": "^17.6.3",
|
|
30
|
+
"@tsconfig/node16": "^16.1.0",
|
|
25
31
|
"@types/jest": "^29.5.1",
|
|
32
|
+
"@types/set-cookie-parser": "^2.4.2",
|
|
26
33
|
"@types/tough-cookie": "^4.0.2",
|
|
27
34
|
"@typescript-eslint/eslint-plugin": "^5.59.7",
|
|
28
35
|
"@typescript-eslint/parser": "^5.59.7",
|