diff --git a/pleroma_bot/_processing.py b/pleroma_bot/_processing.py index 4b319b7..1512180 100644 --- a/pleroma_bot/_processing.py +++ b/pleroma_bot/_processing.py @@ -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: @@ -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: diff --git a/pleroma_bot/_twitter.py b/pleroma_bot/_twitter.py index 6a21570..60ea416 100644 --- a/pleroma_bot/_twitter.py +++ b/pleroma_bot/_twitter.py @@ -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 diff --git a/pleroma_bot/_utils.py b/pleroma_bot/_utils.py index 3b93f27..4f71ee8 100644 --- a/pleroma_bot/_utils.py +++ b/pleroma_bot/_utils.py @@ -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"], diff --git a/pleroma_bot/cli.py b/pleroma_bot/cli.py index 8eb3842..c00a935 100644 --- a/pleroma_bot/cli.py +++ b/pleroma_bot/cli.py @@ -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: