Skip to content

Commit

Permalink
Fix crash on unavailable tweets
Browse files Browse the repository at this point in the history
  • Loading branch information
zedeus committed Feb 25, 2023
1 parent 85f14c9 commit 2751504
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/parser.nim
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ proc parsePhotoRail*(js: JsonNode): PhotoRail =
result.add GalleryPhoto(url: url, tweetId: $t.id)

proc parseGraphTweet(js: JsonNode): Tweet =
if js.kind == JNull:
if js.kind == JNull or js{"__typename"}.getStr == "TweetUnavailable":
return Tweet(available: false)

var jsCard = copy(js{"card", "legacy"})
Expand Down Expand Up @@ -416,6 +416,9 @@ proc parseGraphConversation*(js: JsonNode; tweetId: string): Conversation =
if entryId.startsWith("tweet"):
let tweet = parseGraphTweet(e{"content", "itemContent", "tweet_results", "result"})

if not tweet.available:
tweet.id = parseBiggestInt(entryId.getId())

if $tweet.id == tweetId:
result.tweet = tweet
else:
Expand Down
2 changes: 1 addition & 1 deletion src/types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ type
available*: bool
tombstone*: string
location*: string
## Unused, needed for backwards compat
# Unused, needed for backwards compat
source*: string
stats*: TweetStats
retweet*: Option[Tweet]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

['nim_lang/status/1082989146040340480',
'Nim in 2018: A short recap',
'Posted in r/programming by u/miran1',
'36 votes and 46 comments so far on Reddit',
'reddit.com']
]

Expand Down

0 comments on commit 2751504

Please sign in to comment.