Compare commits

...

2 commits

View file

@ -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) last_posts = mastodon.account_statuses(getenv("MASTODON_USER_ID"), exclude_replies=True, limit=limit)
id_oldest_of_last_posts = -1 id_oldest_of_last_posts = -1
for _ in range(4): 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"] 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) last_posts = mastodon.account_statuses(getenv("MASTODON_USER_ID"), exclude_replies=True, max_id=id_oldest_of_last_posts, limit=limit)
else: else:
@ -36,11 +39,12 @@ def cleanup(limit: int = 40, id: int | None = None):
if len(last_posts) == 0: if len(last_posts) == 0:
return return
# ----- delete old posts ----- # # ----- delete old inactive posts ----- #
# default: check 2 batches of 40 posts (and 6 batches if the id was set manually) # default: check 10 batches of 40 posts
num_batches = 2 if id is None else 6 # this usually tries until the rate limit is triggered or there are no more posts
for i in range(num_batches): # if hitting the rate limit is undesired, reduce the number of iterations
for i in range(10):
# skip getting new batch in the first iteration if the id was set manually # skip getting new batch in the first iteration if the id was set manually
if i != 0 or id is None: if i != 0 or id is None:
# find id of the currently oldest post # find id of the currently oldest post