limit to one tweet per delete round

deleting hundreds of tweets every 40 seconds is making us hit the rate
limit, dont do that
This commit is contained in:
codl 2017-08-29 17:44:50 +02:00
parent 1502f783db
commit 20ed4175e4
No known key found for this signature in database
GPG Key ID: 6CD7C8891ED1233A
1 changed files with 7 additions and 14 deletions

View File

@ -186,11 +186,11 @@ def delete_from_account(account_id):
if account.service == 'twitter':
action = lib.twitter.delete
posts = refresh_posts(posts)
eligible = list(
eligible = random.choice(list( # nosec
(post for post in posts if
(not account.policy_keep_favourites or not post.favourite)
and (not account.policy_keep_media or not post.has_media)
))
)))
elif account.service == 'mastodon':
action = lib.mastodon.delete
for post in posts:
@ -199,21 +199,14 @@ def delete_from_account(account_id):
(not account.policy_keep_favourites or not post.favourite) \
and (not account.policy_keep_media or not post.has_media)\
and (not account.policy_keep_direct or not post.direct):
eligible = refreshed
eligible = refreshed[0]
break
if eligible:
if account.policy_delete_every == timedelta(0) and len(eligible) > 1:
print("deleting all {} eligible posts for {}"
.format(len(eligible), account))
for post in eligible:
account.touch_delete()
action(post)
else:
post = random.choice(eligible) # nosec
print("deleting {}".format(post))
account.touch_delete()
action(post)
post = eligible
print("deleting {}".format(post))
account.touch_delete()
action(post)
db.session.commit()