@the-convocation/twitter-scraper
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -10,6 +11,8 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
import { gotScraping } from 'got-scraping'; | ||
export const bearerToken = 'AAAAAAAAAAAAAAAAAAAAAPYXBAAAAAAACLXUNDekMxqa8h%2F40K4moUkGsoc%3DTYfbDKbT3jJPCEVnMYqilB28NHfOPqkca3qaAxGfsyKCs0wRbw'; | ||
export const bearerToken2 = 'AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA'; | ||
export function requestApi(url, auth) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.addApiParams = exports.requestApi = exports.bearerToken2 = exports.bearerToken = void 0; | ||
const got_scraping_1 = require("got-scraping"); | ||
exports.bearerToken = 'AAAAAAAAAAAAAAAAAAAAAPYXBAAAAAAACLXUNDekMxqa8h%2F40K4moUkGsoc%3DTYfbDKbT3jJPCEVnMYqilB28NHfOPqkca3qaAxGfsyKCs0wRbw'; | ||
exports.bearerToken2 = 'AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA'; | ||
function requestApi(url, auth) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -20,3 +23,3 @@ const headers = {}; | ||
try { | ||
res = yield gotScraping.get({ | ||
res = yield got_scraping_1.gotScraping.get({ | ||
url, | ||
@@ -51,3 +54,4 @@ headers, | ||
} | ||
export function addApiParams(params, includeTweetReplies) { | ||
exports.requestApi = requestApi; | ||
function addApiParams(params, includeTweetReplies) { | ||
params.set('include_profile_interstitial_type', '1'); | ||
@@ -80,2 +84,3 @@ params.set('include_blocking', '1'); | ||
} | ||
exports.addApiParams = addApiParams; | ||
//# sourceMappingURL=api.js.map |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -10,7 +11,9 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
import { gotScraping } from 'got-scraping'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TwitterGuestAuth = void 0; | ||
const got_scraping_1 = require("got-scraping"); | ||
/** | ||
* A guest authentication token manager. Automatically handles token refreshes. | ||
*/ | ||
export class TwitterGuestAuth { | ||
class TwitterGuestAuth { | ||
constructor(bearerToken, cookie, xCsrfToken) { | ||
@@ -88,3 +91,3 @@ this.bearerToken = bearerToken; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const res = yield gotScraping.post({ | ||
const res = yield got_scraping_1.gotScraping.post({ | ||
url: 'https://api.twitter.com/1.1/guest/activate.json', | ||
@@ -121,2 +124,3 @@ headers: { | ||
} | ||
exports.TwitterGuestAuth = TwitterGuestAuth; | ||
//# sourceMappingURL=auth.js.map |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -10,4 +11,6 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
import { requestApi } from './api'; | ||
export function parseProfile(user) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getUserIdByScreenName = exports.getProfile = exports.parseProfile = void 0; | ||
const api_1 = require("./api"); | ||
function parseProfile(user) { | ||
var _a, _b; | ||
@@ -42,5 +45,6 @@ const profile = { | ||
} | ||
export function getProfile(username, auth) { | ||
exports.parseProfile = parseProfile; | ||
function getProfile(username, auth) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const res = yield requestApi('https://api.twitter.com/graphql/4S2ihIKfF3xhp-ENxvUAfQ/UserByScreenName?variables=%7B%22screen_name%22%3A%22' + | ||
const res = yield (0, api_1.requestApi)('https://api.twitter.com/graphql/4S2ihIKfF3xhp-ENxvUAfQ/UserByScreenName?variables=%7B%22screen_name%22%3A%22' + | ||
username + | ||
@@ -80,4 +84,5 @@ '%22%2C%22withHighlightedLabel%22%3Atrue%7D', auth); | ||
} | ||
exports.getProfile = getProfile; | ||
const idCache = new Map(); | ||
export function getUserIdByScreenName(screenName, auth) { | ||
function getUserIdByScreenName(screenName, auth) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -106,2 +111,3 @@ const cached = idCache.get(screenName); | ||
} | ||
exports.getUserIdByScreenName = getUserIdByScreenName; | ||
//# sourceMappingURL=profile.js.map |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -10,8 +11,10 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
import { bearerToken, bearerToken2 } from './api'; | ||
import { TwitterGuestAuth } from './auth'; | ||
import { getProfile, getUserIdByScreenName } from './profile'; | ||
import { fetchSearchProfiles, fetchSearchTweets, SearchMode, searchProfiles, searchTweets, } from './search'; | ||
import { getTrends } from './trends'; | ||
import { getTweet, getTweets } from './tweets'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Scraper = void 0; | ||
const api_1 = require("./api"); | ||
const auth_1 = require("./auth"); | ||
const profile_1 = require("./profile"); | ||
const search_1 = require("./search"); | ||
const trends_1 = require("./trends"); | ||
const tweets_1 = require("./tweets"); | ||
/** | ||
@@ -21,3 +24,3 @@ * An interface to Twitter's undocumented API. | ||
*/ | ||
export class Scraper { | ||
class Scraper { | ||
/** | ||
@@ -28,4 +31,4 @@ * Creates a new Scraper object. Scrapers maintain their own guest tokens for Twitter's internal API. | ||
constructor() { | ||
this.auth = new TwitterGuestAuth(bearerToken); | ||
this.authTrends = new TwitterGuestAuth(bearerToken2); | ||
this.auth = new auth_1.TwitterGuestAuth(api_1.bearerToken); | ||
this.authTrends = new auth_1.TwitterGuestAuth(api_1.bearerToken2); | ||
} | ||
@@ -39,3 +42,3 @@ /** | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const res = yield getProfile(username, this.auth); | ||
const res = yield (0, profile_1.getProfile)(username, this.auth); | ||
return this.handleResponse(res); | ||
@@ -51,3 +54,3 @@ }); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const res = yield getUserIdByScreenName(screenName, this.auth); | ||
const res = yield (0, profile_1.getUserIdByScreenName)(screenName, this.auth); | ||
return this.handleResponse(res); | ||
@@ -64,4 +67,4 @@ }); | ||
*/ | ||
searchTweets(query, maxTweets, includeReplies, searchMode = SearchMode.Top) { | ||
return searchTweets(query, maxTweets, includeReplies, searchMode, this.auth); | ||
searchTweets(query, maxTweets, includeReplies, searchMode = search_1.SearchMode.Top) { | ||
return (0, search_1.searchTweets)(query, maxTweets, includeReplies, searchMode, this.auth); | ||
} | ||
@@ -75,3 +78,3 @@ /** | ||
searchProfiles(query, maxProfiles) { | ||
return searchProfiles(query, maxProfiles, this.auth); | ||
return (0, search_1.searchProfiles)(query, maxProfiles, this.auth); | ||
} | ||
@@ -88,3 +91,3 @@ /** | ||
fetchSearchTweets(query, maxTweets, includeReplies, searchMode, cursor) { | ||
return fetchSearchTweets(query, maxTweets, includeReplies, searchMode, this.auth, cursor); | ||
return (0, search_1.fetchSearchTweets)(query, maxTweets, includeReplies, searchMode, this.auth, cursor); | ||
} | ||
@@ -99,3 +102,3 @@ /** | ||
fetchSearchProfiles(query, maxProfiles, cursor) { | ||
return fetchSearchProfiles(query, maxProfiles, this.auth, cursor); | ||
return (0, search_1.fetchSearchProfiles)(query, maxProfiles, this.auth, cursor); | ||
} | ||
@@ -107,3 +110,3 @@ /** | ||
getTrends() { | ||
return getTrends(this.authTrends); | ||
return (0, trends_1.getTrends)(this.authTrends); | ||
} | ||
@@ -118,3 +121,3 @@ /** | ||
getTweets(user, maxTweets, includeReplies) { | ||
return getTweets(user, maxTweets, includeReplies, this.auth); | ||
return (0, tweets_1.getTweets)(user, maxTweets, includeReplies, this.auth); | ||
} | ||
@@ -128,3 +131,3 @@ /** | ||
getTweet(id, includeReplies) { | ||
return getTweet(id, includeReplies, this.auth); | ||
return (0, tweets_1.getTweet)(id, includeReplies, this.auth); | ||
} | ||
@@ -165,2 +168,3 @@ /** | ||
} | ||
exports.Scraper = Scraper; | ||
//# sourceMappingURL=scraper.js.map |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -10,9 +11,11 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
import { addApiParams, requestApi } from './api'; | ||
import { parseTweets, parseUsers, } from './timeline'; | ||
import { getTweetTimeline, getUserTimeline } from './timeline-async'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.fetchSearchProfiles = exports.fetchSearchTweets = exports.searchProfiles = exports.searchTweets = exports.SearchMode = void 0; | ||
const api_1 = require("./api"); | ||
const timeline_1 = require("./timeline"); | ||
const timeline_async_1 = require("./timeline-async"); | ||
/** | ||
* The categories that can be used in Twitter searches. | ||
*/ | ||
export var SearchMode; | ||
var SearchMode; | ||
(function (SearchMode) { | ||
@@ -24,25 +27,29 @@ SearchMode[SearchMode["Top"] = 0] = "Top"; | ||
SearchMode[SearchMode["Users"] = 4] = "Users"; | ||
})(SearchMode || (SearchMode = {})); | ||
export function searchTweets(query, maxTweets, includeReplies, searchMode, auth) { | ||
return getTweetTimeline(query, maxTweets, (q, mt, c) => { | ||
})(SearchMode = exports.SearchMode || (exports.SearchMode = {})); | ||
function searchTweets(query, maxTweets, includeReplies, searchMode, auth) { | ||
return (0, timeline_async_1.getTweetTimeline)(query, maxTweets, (q, mt, c) => { | ||
return fetchSearchTweets(q, mt, includeReplies, searchMode, auth, c); | ||
}); | ||
} | ||
export function searchProfiles(query, maxProfiles, auth) { | ||
return getUserTimeline(query, maxProfiles, (q, mt, c) => { | ||
exports.searchTweets = searchTweets; | ||
function searchProfiles(query, maxProfiles, auth) { | ||
return (0, timeline_async_1.getUserTimeline)(query, maxProfiles, (q, mt, c) => { | ||
return fetchSearchProfiles(q, mt, auth, c); | ||
}); | ||
} | ||
export function fetchSearchTweets(query, maxTweets, includeReplies, searchMode, auth, cursor) { | ||
exports.searchProfiles = searchProfiles; | ||
function fetchSearchTweets(query, maxTweets, includeReplies, searchMode, auth, cursor) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const timeline = yield getSearchTimeline(query, maxTweets, includeReplies, searchMode, auth, cursor); | ||
return parseTweets(timeline); | ||
return (0, timeline_1.parseTweets)(timeline); | ||
}); | ||
} | ||
export function fetchSearchProfiles(query, maxProfiles, auth, cursor) { | ||
exports.fetchSearchTweets = fetchSearchTweets; | ||
function fetchSearchProfiles(query, maxProfiles, auth, cursor) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const timeline = yield getSearchTimeline(query, maxProfiles, false, SearchMode.Users, auth, cursor); | ||
return parseUsers(timeline); | ||
return (0, timeline_1.parseUsers)(timeline); | ||
}); | ||
} | ||
exports.fetchSearchProfiles = fetchSearchProfiles; | ||
function getSearchTimeline(query, maxItems, includeReplies, searchMode, auth, cursor) { | ||
@@ -54,3 +61,3 @@ return __awaiter(this, void 0, void 0, function* () { | ||
const params = new URLSearchParams(); | ||
addApiParams(params, includeReplies); | ||
(0, api_1.addApiParams)(params, includeReplies); | ||
params.set('q', query); | ||
@@ -80,3 +87,3 @@ params.set('count', `${maxItems}`); | ||
} | ||
const res = yield requestApi(`https://twitter.com/i/api/2/search/adaptive.json?${params.toString()}`, auth); | ||
const res = yield (0, api_1.requestApi)(`https://twitter.com/i/api/2/search/adaptive.json?${params.toString()}`, auth); | ||
if (!res.success) { | ||
@@ -83,0 +90,0 @@ throw res.err; |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); } | ||
@@ -13,3 +14,5 @@ var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) { | ||
}; | ||
export function getUserTimeline(query, maxProfiles, fetchFunc) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getTweetTimeline = exports.getUserTimeline = void 0; | ||
function getUserTimeline(query, maxProfiles, fetchFunc) { | ||
return __asyncGenerator(this, arguments, function* getUserTimeline_1() { | ||
@@ -37,3 +40,4 @@ let nProfiles = 0; | ||
} | ||
export function getTweetTimeline(query, maxTweets, fetchFunc) { | ||
exports.getUserTimeline = getUserTimeline; | ||
function getTweetTimeline(query, maxTweets, fetchFunc) { | ||
return __asyncGenerator(this, arguments, function* getTweetTimeline_1() { | ||
@@ -61,2 +65,3 @@ let nTweets = 0; | ||
} | ||
exports.getTweetTimeline = getTweetTimeline; | ||
//# sourceMappingURL=timeline-async.js.map |
@@ -1,6 +0,9 @@ | ||
import { parseProfile } from './profile'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parseUsers = exports.parseTweets = exports.parseTweet = void 0; | ||
const profile_1 = require("./profile"); | ||
const reHashtag = /\B(\#\S+\b)/g; | ||
const reTwitterUrl = /https:(\/\/t\.co\/([A-Za-z0-9]|[A-Za-z]){10})/g; | ||
const reUsername = /\B(\@\S{1,15}\b)/g; | ||
export function parseTweet(timeline, id) { | ||
function parseTweet(timeline, id) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q; | ||
@@ -153,3 +156,4 @@ const tweets = (_b = (_a = timeline.globalObjects) === null || _a === void 0 ? void 0 : _a.tweets) !== null && _b !== void 0 ? _b : {}; | ||
} | ||
export function parseTweets(timeline) { | ||
exports.parseTweet = parseTweet; | ||
function parseTweets(timeline) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w; | ||
@@ -193,3 +197,4 @@ let cursor; | ||
} | ||
export function parseUsers(timeline) { | ||
exports.parseTweets = parseTweets; | ||
function parseUsers(timeline) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s; | ||
@@ -203,3 +208,3 @@ const users = new Map(); | ||
} | ||
const user = parseProfile(legacy); | ||
const user = (0, profile_1.parseProfile)(legacy); | ||
users.set(id, user); | ||
@@ -231,2 +236,3 @@ } | ||
} | ||
exports.parseUsers = parseUsers; | ||
//# sourceMappingURL=timeline.js.map |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -10,8 +11,10 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
import { addApiParams, requestApi } from './api'; | ||
export function getTrends(auth) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getTrends = void 0; | ||
const api_1 = require("./api"); | ||
function getTrends(auth) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const params = new URLSearchParams(); | ||
addApiParams(params, false); | ||
(0, api_1.addApiParams)(params, false); | ||
params.set('count', '20'); | ||
@@ -21,3 +24,3 @@ params.set('candidate_source', 'trends'); | ||
params.set('entity_tokens', 'false'); | ||
const res = yield requestApi(`https://twitter.com/i/api/2/guide.json?${params.toString()}`, auth); | ||
const res = yield (0, api_1.requestApi)(`https://twitter.com/i/api/2/guide.json?${params.toString()}`, auth); | ||
if (!res.success) { | ||
@@ -48,2 +51,3 @@ throw res.err; | ||
} | ||
exports.getTrends = getTrends; | ||
//# sourceMappingURL=trends.js.map |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -10,7 +11,9 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
import { addApiParams, requestApi } from './api'; | ||
import { getUserIdByScreenName } from './profile'; | ||
import { parseTweets } from './timeline'; | ||
import { getTweetTimeline } from './timeline-async'; | ||
export function fetchTweets(user, maxTweets, includeReplies, cursor, auth) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getTweet = exports.getTweets = exports.fetchTweets = void 0; | ||
const api_1 = require("./api"); | ||
const profile_1 = require("./profile"); | ||
const timeline_1 = require("./timeline"); | ||
const timeline_async_1 = require("./timeline-async"); | ||
function fetchTweets(user, maxTweets, includeReplies, cursor, auth) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -20,3 +23,3 @@ if (maxTweets > 200) { | ||
} | ||
const userIdRes = yield getUserIdByScreenName(user, auth); | ||
const userIdRes = yield (0, profile_1.getUserIdByScreenName)(user, auth); | ||
if (!userIdRes.success) { | ||
@@ -26,3 +29,3 @@ throw userIdRes.err; | ||
const params = new URLSearchParams(); | ||
addApiParams(params, includeReplies); | ||
(0, api_1.addApiParams)(params, includeReplies); | ||
params.set('count', `${maxTweets}`); | ||
@@ -33,23 +36,25 @@ params.set('userId', userIdRes.value); | ||
} | ||
const res = yield requestApi(`https://api.twitter.com/2/timeline/profile/${userIdRes.value}.json?${params.toString()}`, auth); | ||
const res = yield (0, api_1.requestApi)(`https://api.twitter.com/2/timeline/profile/${userIdRes.value}.json?${params.toString()}`, auth); | ||
if (!res.success) { | ||
throw res.err; | ||
} | ||
return parseTweets(res.value); | ||
return (0, timeline_1.parseTweets)(res.value); | ||
}); | ||
} | ||
export function getTweets(user, maxTweets, includeReplies, auth) { | ||
return getTweetTimeline(user, maxTweets, (q, mt, c) => { | ||
exports.fetchTweets = fetchTweets; | ||
function getTweets(user, maxTweets, includeReplies, auth) { | ||
return (0, timeline_async_1.getTweetTimeline)(user, maxTweets, (q, mt, c) => { | ||
return fetchTweets(q, mt, includeReplies, c, auth); | ||
}); | ||
} | ||
export function getTweet(id, includeReplies, auth) { | ||
exports.getTweets = getTweets; | ||
function getTweet(id, includeReplies, auth) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const params = new URLSearchParams(); | ||
addApiParams(params, includeReplies); | ||
const res = yield requestApi(`https://twitter.com/i/api/2/timeline/conversation/${id}.json?${params.toString()}`, auth); | ||
(0, api_1.addApiParams)(params, includeReplies); | ||
const res = yield (0, api_1.requestApi)(`https://twitter.com/i/api/2/timeline/conversation/${id}.json?${params.toString()}`, auth); | ||
if (!res.success) { | ||
throw res.err; | ||
} | ||
const { tweets } = parseTweets(res.value); | ||
const { tweets } = (0, timeline_1.parseTweets)(res.value); | ||
for (const tweet of tweets) { | ||
@@ -63,2 +68,3 @@ if (tweet.id === id) { | ||
} | ||
exports.getTweet = getTweet; | ||
//# sourceMappingURL=tweets.js.map |
{ | ||
"name": "@the-convocation/twitter-scraper", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"main": "dist/scraper.js", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/the-convocation/twitter-scraper.git", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
102011
1442