fix #7 - comply with API rate limit

This commit is contained in:
Hugh Rundle 2019-05-10 07:58:59 +10:00
parent 357455126c
commit bb1f7ffecf
1 changed files with 16 additions and 1 deletions

View File

@ -26,6 +26,7 @@ import config
import json
from mastodon import Mastodon
from datetime import datetime, timedelta, timezone
import time
parser = ArgumentParser()
parser.add_argument(
@ -72,7 +73,21 @@ def checkToots(timeline, deleted_count=0):
)
deleted_count += 1
if not options.test:
mastodon.status_delete(toot)
# the delete API call is limited to 30 deletions every 30 minutes
if (deleted_count == 30) or (
deleted_count > 30 and (deleted_count % 30 == 0)
):
mastodon.status_delete(toot)
print(
"waiting 30 minutes: API limit reached at "
+ str(deleted_count)
+ " deletions"
)
time.sleep(
1805
) # wait 30 minnutes with 5 extra seconds leeway
else:
mastodon.status_delete(toot)
except:
print("🛑 **error** with toot - " + str(toot.id))