Skip to content

Commit

Permalink
chore: yarn format
Browse files Browse the repository at this point in the history
  • Loading branch information
karashiiro committed Feb 25, 2024
1 parent a6f4ba8 commit 2dd036a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/scraper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ export class Scraper {
* @returns A page of results, containing a cursor that can be used in further requests.
*/
public fetchListTweets(
listId: string,
maxTweets: number,
cursor?: string,
listId: string,
maxTweets: number,
cursor?: string,
): Promise<QueryTweetsResponse> {
return fetchListTweets(listId, maxTweets, cursor, this.auth);
}
Expand Down
22 changes: 16 additions & 6 deletions src/timeline-list.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { QueryTweetsResponse } from './timeline-v1';
import {parseAndPush, TimelineEntryRaw} from './timeline-v2';
import { parseAndPush, TimelineEntryRaw } from './timeline-v2';
import { Tweet } from './tweets';

export interface ListTimeline {
Expand All @@ -25,8 +25,7 @@ export function parseListTimelineTweets(
let topCursor: string | undefined;
const tweets: Tweet[] = [];
const instructions =
timeline.data?.list?.tweets_timeline?.timeline
?.instructions ?? [];
timeline.data?.list?.tweets_timeline?.timeline?.instructions ?? [];
for (const instruction of instructions) {
const entries = instruction.entries ?? [];

Expand All @@ -43,16 +42,27 @@ export function parseListTimelineTweets(
}

const idStr = entry.entryId;
if (!idStr.startsWith('tweet') && !idStr.startsWith('list-conversation')) {
if (
!idStr.startsWith('tweet') &&
!idStr.startsWith('list-conversation')
) {
continue;
}

if (entryContent.itemContent) {
parseAndPush(tweets, entryContent.itemContent, idStr);
} else if (entryContent.items) {
for (const contentItem of entryContent.items) {
if (contentItem.item && contentItem.item.itemContent && contentItem.entryId) {
parseAndPush(tweets, contentItem.item.itemContent, contentItem.entryId.split('tweet-')[1]);
if (
contentItem.item &&
contentItem.item.itemContent &&
contentItem.entryId
) {
parseAndPush(
tweets,
contentItem.item.itemContent,
contentItem.entryId.split('tweet-')[1],
);
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/tweets.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getScraper } from './test-utils';
import { Mention, Tweet } from './tweets';
import {QueryTweetsResponse} from "./timeline-v1";
import {SearchMode} from "./search";
import { QueryTweetsResponse } from './timeline-v1';
import { SearchMode } from './search';

test('scraper can get tweet', async () => {
const expected: Tweet = {
Expand Down Expand Up @@ -60,9 +60,9 @@ test('scraper can get tweets from list', async () => {
let nTweets = 0;
while (nTweets < maxTweets) {
const res: QueryTweetsResponse = await scraper.fetchListTweets(
'1736495155002106192',
maxTweets,
cursor,
'1736495155002106192',
maxTweets,
cursor,
);

expect(res.next).toBeTruthy();
Expand Down
14 changes: 7 additions & 7 deletions src/tweets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from './timeline-v2';
import { getTweetTimeline } from './timeline-async';
import { apiRequestFactory } from './api-data';
import {ListTimeline, parseListTimelineTweets} from "./timeline-list";
import { ListTimeline, parseListTimelineTweets } from './timeline-list';

export interface Mention {
id: string;
Expand Down Expand Up @@ -129,10 +129,10 @@ export async function fetchTweets(
}

export async function fetchListTweets(
listId: string,
maxTweets: number,
cursor: string | undefined,
auth: TwitterAuth,
listId: string,
maxTweets: number,
cursor: string | undefined,
auth: TwitterAuth,
): Promise<QueryTweetsResponse> {
if (maxTweets > 200) {
maxTweets = 200;
Expand All @@ -147,8 +147,8 @@ export async function fetchListTweets(
}

const res = await requestApi<ListTimeline>(
listTweetsRequest.toRequestUrl(),
auth,
listTweetsRequest.toRequestUrl(),
auth,
);

if (!res.success) {
Expand Down

0 comments on commit 2dd036a

Please sign in to comment.