Skip to content

Commit e40c61a

Browse files
authored
Find TimelineAddEntries in tweets response (zedeus#1251)
See zedeus#1250. Sometimes the API gives us more results and the tweets are no longer at index 0.
1 parent 94c83f3 commit e40c61a

File tree

1 file changed

+35
-33
lines changed

1 file changed

+35
-33
lines changed

src/parser.nim

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -364,39 +364,41 @@ proc parseGraphConversation*(js: JsonNode; tweetId: string; v2=true): Conversati
364364
if instructions.len == 0:
365365
return
366366

367-
for e in instructions[0]{"entries"}:
368-
let entryId = e{"entryId"}.getStr
369-
if entryId.startsWith("tweet"):
370-
with tweetResult, e{"content", contentKey, resultKey, "result"}:
371-
let tweet = parseGraphTweet(tweetResult, not v2)
372-
373-
if not tweet.available:
374-
tweet.id = parseBiggestInt(entryId.getId())
375-
376-
if $tweet.id == tweetId:
377-
result.tweet = tweet
378-
else:
379-
result.before.content.add tweet
380-
elif entryId.startsWith("conversationthread"):
381-
let (thread, self) = parseGraphThread(e)
382-
if self:
383-
result.after = thread
384-
elif thread.content.len > 0:
385-
result.replies.content.add thread
386-
elif entryId.startsWith("tombstone"):
387-
let id = entryId.getId()
388-
let tweet = Tweet(
389-
id: parseBiggestInt(id),
390-
available: false,
391-
text: e{"content", contentKey, "tombstoneInfo", "richText"}.getTombstone
392-
)
393-
394-
if id == tweetId:
395-
result.tweet = tweet
396-
else:
397-
result.before.content.add tweet
398-
elif entryId.startsWith("cursor-bottom"):
399-
result.replies.bottom = e{"content", contentKey, "value"}.getStr
367+
for i in instructions:
368+
if i{"__typename"}.getStr == "TimelineAddEntries":
369+
for e in i{"entries"}:
370+
let entryId = e{"entryId"}.getStr
371+
if entryId.startsWith("tweet"):
372+
with tweetResult, e{"content", contentKey, resultKey, "result"}:
373+
let tweet = parseGraphTweet(tweetResult, not v2)
374+
375+
if not tweet.available:
376+
tweet.id = parseBiggestInt(entryId.getId())
377+
378+
if $tweet.id == tweetId:
379+
result.tweet = tweet
380+
else:
381+
result.before.content.add tweet
382+
elif entryId.startsWith("conversationthread"):
383+
let (thread, self) = parseGraphThread(e)
384+
if self:
385+
result.after = thread
386+
elif thread.content.len > 0:
387+
result.replies.content.add thread
388+
elif entryId.startsWith("tombstone"):
389+
let id = entryId.getId()
390+
let tweet = Tweet(
391+
id: parseBiggestInt(id),
392+
available: false,
393+
text: e{"content", contentKey, "tombstoneInfo", "richText"}.getTombstone
394+
)
395+
396+
if id == tweetId:
397+
result.tweet = tweet
398+
else:
399+
result.before.content.add tweet
400+
elif entryId.startsWith("cursor-bottom"):
401+
result.replies.bottom = e{"content", contentKey, "value"}.getStr
400402

401403
proc parseGraphTimeline*(js: JsonNode; root: string; after=""): Profile =
402404
result = Profile(tweets: Timeline(beginning: after.len == 0))

0 commit comments

Comments
 (0)