From 2751504d2f41d2fba8d4ef74a5ac413833750c00 Mon Sep 17 00:00:00 2001 From: Zed Date: Sat, 25 Feb 2023 18:25:02 +0100 Subject: [PATCH] Fix crash on unavailable tweets --- src/parser.nim | 5 ++++- src/types.nim | 2 +- tests/test_card.py | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/parser.nim b/src/parser.nim index 544f943..6a77a5f 100644 --- a/src/parser.nim +++ b/src/parser.nim @@ -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"}) @@ -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: diff --git a/src/types.nim b/src/types.nim index b5353b5..625dcb0 100644 --- a/src/types.nim +++ b/src/types.nim @@ -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] diff --git a/tests/test_card.py b/tests/test_card.py index ab79e9c..77e44e1 100644 --- a/tests/test_card.py +++ b/tests/test_card.py @@ -42,7 +42,7 @@ no_thumb = [ ['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'] ]