diff --git a/cleanup.py b/cleanup.py index 851b263..323b2cb 100644 --- a/cleanup.py +++ b/cleanup.py @@ -26,6 +26,9 @@ def cleanup(limit: int = 40, id: int | None = None): last_posts = mastodon.account_statuses(getenv("MASTODON_USER_ID"), exclude_replies=True, limit=limit) id_oldest_of_last_posts = -1 for _ in range(4): + # return if there are no posts to check + if len(last_posts) == 0: + return id_oldest_of_last_posts = last_posts[-1]["id"] last_posts = mastodon.account_statuses(getenv("MASTODON_USER_ID"), exclude_replies=True, max_id=id_oldest_of_last_posts, limit=limit) else: