Skip to content

Commit

Permalink
Explicit error when TwitterGuestAPIScraper.tweet does not find tweet
Browse files Browse the repository at this point in the history
Fix #932
  • Loading branch information
Yomguithereal committed Feb 15, 2024
1 parent ff0efcc commit 421bf06
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions minet/twitter/api_scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
TwitterPublicAPIInvalidCookieError,
TwitterPublicAPIBadAuthError,
TwitterPublicAPINotWorkingAnymore,
TwitterPublicAPINotFound
)

# =============================================================================
Expand Down Expand Up @@ -933,6 +934,10 @@ def tweet(self, tweet_id, locale=None):
data = self.api_call(url)

tweet_root = getpath(data, ("data", "tweetResult", "result"))

if tweet_root is None:
raise TwitterPublicAPINotFound(tweet_id)

tweet = recombobulate_tweet(tweet_root)
tweet = normalize_tweet(
tweet,
Expand Down
3 changes: 3 additions & 0 deletions minet/twitter/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,6 @@ class TwitterPublicAPIHiccupError(TwitterPublicAPIError):

class TwitterPublicAPINotWorkingAnymore(TwitterPublicAPIError):
pass

class TwitterPublicAPINotFound(TwitterPublicAPIError):
pass

0 comments on commit 421bf06

Please sign in to comment.