@the-convocation/twitter-scraper 0.1.4 → 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/README.md +4 -1
- package/dist/api.d.ts +2 -2
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +39 -43
- package/dist/api.js.map +1 -1
- package/dist/auth-user.d.ts +14 -0
- package/dist/auth-user.d.ts.map +1 -0
- package/dist/auth-user.js +204 -0
- package/dist/auth-user.js.map +1 -0
- package/dist/auth.d.ts +45 -28
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +62 -81
- package/dist/auth.js.map +1 -1
- package/dist/errors.d.ts +5 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +11 -0
- package/dist/errors.js.map +1 -0
- package/dist/profile.d.ts +3 -3
- 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 +50 -4
- package/dist/scraper.d.ts.map +1 -1
- package/dist/scraper.js +88 -27
- package/dist/scraper.js.map +1 -1
- package/dist/search.d.ts +5 -5
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +46 -58
- package/dist/search.js.map +1 -1
- package/dist/timeline-async.d.ts.map +1 -1
- package/dist/timeline-async.js +34 -56
- package/dist/timeline-async.js.map +1 -1
- package/dist/timeline.d.ts +19 -1
- package/dist/timeline.d.ts.map +1 -1
- package/dist/timeline.js +157 -116
- package/dist/timeline.js.map +1 -1
- package/dist/trends.d.ts +2 -2
- package/dist/trends.d.ts.map +1 -1
- package/dist/trends.js +31 -42
- package/dist/trends.js.map +1 -1
- package/dist/tweets.d.ts +19 -5
- package/dist/tweets.d.ts.map +1 -1
- package/dist/tweets.js +54 -46
- package/dist/tweets.js.map +1 -1
- package/package.json +21 -13
package/dist/tweets.js
CHANGED
|
@@ -1,65 +1,73 @@
|
|
|
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
|
-
exports.getTweet = exports.getTweets = exports.fetchTweets = void 0;
|
|
3
|
+
exports.getTweet = exports.getLatestTweet = exports.getTweetsByUserId = exports.getTweets = exports.fetchTweets = void 0;
|
|
13
4
|
const api_1 = require("./api");
|
|
14
5
|
const profile_1 = require("./profile");
|
|
15
6
|
const timeline_1 = require("./timeline");
|
|
16
7
|
const timeline_async_1 = require("./timeline-async");
|
|
17
|
-
function fetchTweets(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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);
|
|
24
|
+
}
|
|
25
|
+
exports.fetchTweets = fetchTweets;
|
|
26
|
+
function getTweets(user, maxTweets, includeReplies, auth) {
|
|
27
|
+
return (0, timeline_async_1.getTweetTimeline)(user, maxTweets, async (q, mt, c) => {
|
|
28
|
+
const userIdRes = await (0, profile_1.getUserIdByScreenName)(q, auth);
|
|
23
29
|
if (!userIdRes.success) {
|
|
24
30
|
throw userIdRes.err;
|
|
25
31
|
}
|
|
26
|
-
const
|
|
27
|
-
(
|
|
28
|
-
params.set('count', `${maxTweets}`);
|
|
29
|
-
params.set('userId', userIdRes.value);
|
|
30
|
-
if (cursor != null && cursor != '') {
|
|
31
|
-
params.set('cursor', cursor);
|
|
32
|
-
}
|
|
33
|
-
const res = yield (0, api_1.requestApi)(`https://api.twitter.com/2/timeline/profile/${userIdRes.value}.json?${params.toString()}`, auth);
|
|
34
|
-
if (!res.success) {
|
|
35
|
-
throw res.err;
|
|
36
|
-
}
|
|
37
|
-
return (0, timeline_1.parseTweets)(res.value);
|
|
32
|
+
const { value: userId } = userIdRes;
|
|
33
|
+
return fetchTweets(userId, mt, includeReplies, c, auth);
|
|
38
34
|
});
|
|
39
35
|
}
|
|
40
|
-
exports.
|
|
41
|
-
function
|
|
42
|
-
return (0, timeline_async_1.getTweetTimeline)(
|
|
36
|
+
exports.getTweets = getTweets;
|
|
37
|
+
function getTweetsByUserId(userId, maxTweets, includeReplies, auth) {
|
|
38
|
+
return (0, timeline_async_1.getTweetTimeline)(userId, maxTweets, (q, mt, c) => {
|
|
43
39
|
return fetchTweets(q, mt, includeReplies, c, auth);
|
|
44
40
|
});
|
|
45
41
|
}
|
|
46
|
-
exports.
|
|
47
|
-
function
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
42
|
+
exports.getTweetsByUserId = getTweetsByUserId;
|
|
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;
|
|
54
52
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
exports.getLatestTweet = getLatestTweet;
|
|
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;
|
|
60
68
|
}
|
|
61
|
-
|
|
62
|
-
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
63
71
|
}
|
|
64
72
|
exports.getTweet = getTweet;
|
|
65
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,CA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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,27 +18,32 @@
|
|
|
15
18
|
"test": "jest"
|
|
16
19
|
},
|
|
17
20
|
"dependencies": {
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
+
"cross-fetch": "^4.0.0-alpha.5",
|
|
22
|
+
"headers-polyfill": "^3.1.2",
|
|
23
|
+
"set-cookie-parser": "^2.6.0",
|
|
24
|
+
"tough-cookie": "^4.1.2",
|
|
25
|
+
"tslib": "^2.5.2"
|
|
21
26
|
},
|
|
22
27
|
"devDependencies": {
|
|
23
|
-
"@commitlint/cli": "^17.6.
|
|
24
|
-
"@commitlint/config-conventional": "^17.6.
|
|
25
|
-
"@
|
|
26
|
-
"@
|
|
27
|
-
"@
|
|
28
|
+
"@commitlint/cli": "^17.6.3",
|
|
29
|
+
"@commitlint/config-conventional": "^17.6.3",
|
|
30
|
+
"@tsconfig/node16": "^16.1.0",
|
|
31
|
+
"@types/jest": "^29.5.1",
|
|
32
|
+
"@types/set-cookie-parser": "^2.4.2",
|
|
33
|
+
"@types/tough-cookie": "^4.0.2",
|
|
34
|
+
"@typescript-eslint/eslint-plugin": "^5.59.7",
|
|
35
|
+
"@typescript-eslint/parser": "^5.59.7",
|
|
28
36
|
"cz-conventional-changelog": "^3.3.0",
|
|
29
|
-
"eslint": "^8.
|
|
37
|
+
"eslint": "^8.41.0",
|
|
30
38
|
"eslint-config-prettier": "^8.8.0",
|
|
31
39
|
"eslint-plugin-prettier": "^4.2.1",
|
|
32
40
|
"gh-pages": "^5.0.0",
|
|
33
41
|
"husky": "^8.0.3",
|
|
34
42
|
"jest": "^29.5.0",
|
|
35
|
-
"lint-staged": "^13.2.
|
|
36
|
-
"prettier": "^2.8.
|
|
43
|
+
"lint-staged": "^13.2.2",
|
|
44
|
+
"prettier": "^2.8.8",
|
|
37
45
|
"ts-jest": "^29.1.0",
|
|
38
|
-
"typedoc": "^0.24.
|
|
46
|
+
"typedoc": "^0.24.7",
|
|
39
47
|
"typescript": "^5.0.4"
|
|
40
48
|
},
|
|
41
49
|
"config": {
|