Improved logging

This commit is contained in:
lluni 2023-08-03 00:24:28 +02:00
parent cc30007584
commit 404f9f0928
Signed by: lluni
GPG key ID: ACEEB468BC325D35

View file

@ -40,19 +40,20 @@ def cleanup(offset: int = 200, limit: int = 40, id: int | None = None):
iterations = offset // 40 iterations = offset // 40
remainder = offset % 40 remainder = offset % 40
# get latest posts until offset is reached # get latest posts until offset is reached
for _ in range(iterations): for i in range(iterations):
last_posts = get_account_statuses(max_id=id_oldest_of_last_posts, limit=40) last_posts = get_account_statuses(max_id=id_oldest_of_last_posts, limit=40)
if len(last_posts) == 0: if len(last_posts) == 0:
print("Offset is higher than the number of posts in the past.") print("Offset is higher than the number of posts in the past.")
return return
id_oldest_of_last_posts = last_posts[-1]["id"] id_oldest_of_last_posts = last_posts[-1]["id"]
print("Last post:", last_posts[-1]["url"]) print(f"Currently at offset {(i + 1) * 40}, last ignored post: {last_posts[-1]['url']}")
if remainder != 0: if remainder != 0:
last_posts = get_account_statuses(max_id=id_oldest_of_last_posts, limit=remainder) last_posts = get_account_statuses(max_id=id_oldest_of_last_posts, limit=remainder)
if len(last_posts) == 0: if len(last_posts) == 0:
print("Offset is higher than the number of posts in the past.") print("Offset is higher than the number of posts in the past.")
return return
id_oldest_of_last_posts = last_posts[-1]["id"] id_oldest_of_last_posts = last_posts[-1]["id"]
print(f"Currently at offset {iterations * 40 + remainder}, last ignored post: {last_posts[-1]['url']}")
else: else:
id_oldest_of_last_posts = id id_oldest_of_last_posts = id
last_posts = mastodon.account_statuses(getenv("MASTODON_USER_ID"), exclude_replies=True, max_id=id, limit=limit) last_posts = mastodon.account_statuses(getenv("MASTODON_USER_ID"), exclude_replies=True, max_id=id, limit=limit)