Skip to content

Commit

Permalink
try handling 404 when getting tweet with id
Browse files Browse the repository at this point in the history
  • Loading branch information
robertoszek committed Dec 6, 2022
1 parent b70327d commit 812e94b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pleroma_bot/_processing.py
Expand Up @@ -235,7 +235,8 @@ def _get_rt_text(self, tweet): # pragma: no cover
if retweeted or quoted:
tweet_ref_id = reference["id"]
tweet_ref = self._get_tweets("v2", tweet_ref_id)

if not tweet_ref: # pragma: todo
continue
match = re.search(r"RT.*?\:", tweet["text"])
prefix = match.group() if match else ""
if retweeted:
Expand Down Expand Up @@ -263,6 +264,8 @@ def _get_rt_media_url(self, tweet, media): # pragma: no cover
if retweeted or quoted:
tweet_id = reference["id"]
tweet_rt = self._get_tweets("v2", tweet_id)
if not tweet_rt:
continue
tw_data = tweet_rt["data"]
att = "attachments" in tw_data.keys()
if att:
Expand Down
8 changes: 8 additions & 0 deletions pleroma_bot/_twitter.py
Expand Up @@ -429,6 +429,14 @@ def _get_tweets(
auth=self.auth
)
if not response.ok:
if response.status_code == 404: # pragma: todo
logger.warning(
_(
"Received HTTP 404 when trying to get tweet."
" Tweet deleted? Skipping..."
)
)
return None
response.raise_for_status()
tweet = response.json()
if self.guest: # pragma: todo
Expand Down
2 changes: 2 additions & 0 deletions pleroma_bot/_utils.py
Expand Up @@ -356,6 +356,8 @@ def check_pinned(self, posted=None):
id_post_to_pin = posted[self.pinned_tweet_id]
else:
pinned_tweet = self._get_tweets("v2", self.pinned_tweet_id)
if not pinned_tweet: # pragma: todo
return
tweets_to_post = {
"data": [pinned_tweet["data"]],
"includes": pinned_tweet["includes"],
Expand Down
2 changes: 2 additions & 0 deletions pleroma_bot/cli.py
Expand Up @@ -589,6 +589,8 @@ def main():
tweets["includes"].update({include: []})
for tweet_id in user.tweet_ids:
next_tweet = user._get_tweets("v2", tweet_id=tweet_id)
if not next_tweet: # pragma: todo
continue
includes = ["users", "tweets", "media", "polls"]
for include in includes:
try:
Expand Down

0 comments on commit 812e94b

Please sign in to comment.