Find TimelineAddEntries in tweets response (#1251)

See https://github.com/zedeus/nitter/issues/1250. Sometimes the API gives us more results
and the tweets are no longer at index 0.
This commit is contained in:
Gabriel Simmer
2025-05-01 12:39:05 +01:00
committed by GitHub
parent 94c83f3811
commit e40c61a6ae

View File

@@ -364,39 +364,41 @@ proc parseGraphConversation*(js: JsonNode; tweetId: string; v2=true): Conversati
if instructions.len == 0: if instructions.len == 0:
return return
for e in instructions[0]{"entries"}: for i in instructions:
let entryId = e{"entryId"}.getStr if i{"__typename"}.getStr == "TimelineAddEntries":
if entryId.startsWith("tweet"): for e in i{"entries"}:
with tweetResult, e{"content", contentKey, resultKey, "result"}: let entryId = e{"entryId"}.getStr
let tweet = parseGraphTweet(tweetResult, not v2) if entryId.startsWith("tweet"):
with tweetResult, e{"content", contentKey, resultKey, "result"}:
let tweet = parseGraphTweet(tweetResult, not v2)
if not tweet.available: if not tweet.available:
tweet.id = parseBiggestInt(entryId.getId()) tweet.id = parseBiggestInt(entryId.getId())
if $tweet.id == tweetId: if $tweet.id == tweetId:
result.tweet = tweet result.tweet = tweet
else: else:
result.before.content.add tweet result.before.content.add tweet
elif entryId.startsWith("conversationthread"): elif entryId.startsWith("conversationthread"):
let (thread, self) = parseGraphThread(e) let (thread, self) = parseGraphThread(e)
if self: if self:
result.after = thread result.after = thread
elif thread.content.len > 0: elif thread.content.len > 0:
result.replies.content.add thread result.replies.content.add thread
elif entryId.startsWith("tombstone"): elif entryId.startsWith("tombstone"):
let id = entryId.getId() let id = entryId.getId()
let tweet = Tweet( let tweet = Tweet(
id: parseBiggestInt(id), id: parseBiggestInt(id),
available: false, available: false,
text: e{"content", contentKey, "tombstoneInfo", "richText"}.getTombstone text: e{"content", contentKey, "tombstoneInfo", "richText"}.getTombstone
) )
if id == tweetId: if id == tweetId:
result.tweet = tweet result.tweet = tweet
else: else:
result.before.content.add tweet result.before.content.add tweet
elif entryId.startsWith("cursor-bottom"): elif entryId.startsWith("cursor-bottom"):
result.replies.bottom = e{"content", contentKey, "value"}.getStr result.replies.bottom = e{"content", contentKey, "value"}.getStr
proc parseGraphTimeline*(js: JsonNode; root: string; after=""): Profile = proc parseGraphTimeline*(js: JsonNode; root: string; after=""): Profile =
result = Profile(tweets: Timeline(beginning: after.len == 0)) result = Profile(tweets: Timeline(beginning: after.len == 0))