-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add fetchListTweets function to get tweets from list
- Loading branch information
1 parent
88de07d
commit 6cc1c5b
Showing
6 changed files
with
130 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { QueryTweetsResponse } from './timeline-v1'; | ||
import { SearchEntryRaw, parseAndPush } from './timeline-v2'; | ||
import { Tweet } from './tweets'; | ||
|
||
export interface ListTimeline { | ||
data?: { | ||
list?: { | ||
tweets_timeline?: { | ||
timeline?: { | ||
instructions?: { | ||
entries?: SearchEntryRaw[]; | ||
entry?: SearchEntryRaw; | ||
type?: string; | ||
}[]; | ||
}; | ||
}; | ||
}; | ||
}; | ||
} | ||
|
||
export function parseListTimelineTweets( | ||
timeline: ListTimeline, | ||
): QueryTweetsResponse { | ||
let bottomCursor: string | undefined; | ||
let topCursor: string | undefined; | ||
const tweets: Tweet[] = []; | ||
const instructions = | ||
timeline.data?.list?.tweets_timeline?.timeline | ||
?.instructions ?? []; | ||
for (const instruction of instructions) { | ||
const entries = instruction.entries ?? []; | ||
|
||
for (const entry of entries) { | ||
const entryContent = entry.content; | ||
if (!entryContent) continue; | ||
|
||
if (entryContent.cursorType === 'Bottom') { | ||
bottomCursor = entryContent.value; | ||
continue; | ||
} else if (entryContent.cursorType === 'Top') { | ||
topCursor = entryContent.value; | ||
continue; | ||
} | ||
|
||
const idStr = entry.entryId; | ||
if (!idStr.startsWith('tweet')) { | ||
continue; | ||
} | ||
|
||
if (entryContent.itemContent) { | ||
parseAndPush(tweets, entryContent.itemContent, idStr); | ||
} | ||
} | ||
} | ||
|
||
return { tweets, next: bottomCursor, previous: topCursor }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters