mirror of
https://github.com/hughrun/ephemetoot
synced 2025-02-14 10:20:36 +01:00
Merge pull request #2 from MarkEEaton/master
run black on ephemetoot.py to improve code readability
This commit is contained in:
commit
6b39f5b8e6
@ -27,52 +27,61 @@ import json
|
|||||||
from mastodon import Mastodon
|
from mastodon import Mastodon
|
||||||
from datetime import datetime, timedelta, timezone
|
from datetime import datetime, timedelta, timezone
|
||||||
|
|
||||||
print('Fetching account details...')
|
print("Fetching account details...")
|
||||||
|
|
||||||
mastodon = Mastodon(
|
mastodon = Mastodon(access_token=config.access_token, api_base_url=config.base_url)
|
||||||
access_token = config.access_token,
|
|
||||||
api_base_url = config.base_url
|
|
||||||
)
|
|
||||||
|
|
||||||
cutoff_date = datetime.now(timezone.utc) - timedelta(days=config.days_to_keep)
|
cutoff_date = datetime.now(timezone.utc) - timedelta(days=config.days_to_keep)
|
||||||
user_id = mastodon.account_verify_credentials().id
|
user_id = mastodon.account_verify_credentials().id
|
||||||
timeline = mastodon.account_statuses(user_id, limit=40)
|
timeline = mastodon.account_statuses(user_id, limit=40)
|
||||||
|
|
||||||
def checkToots(timeline, deleted_count=0):
|
|
||||||
for toot in timeline:
|
|
||||||
try:
|
|
||||||
if (config.save_pinned and hasattr(toot, 'pinned') and toot.pinned):
|
|
||||||
print('📌 skipping pinned toot - ' + str(toot.id))
|
|
||||||
elif toot.id in config.toots_to_save:
|
|
||||||
print('💾 skipping saved toot - ' + str(toot.id))
|
|
||||||
elif (cutoff_date > toot.created_at):
|
|
||||||
if hasattr(toot, 'reblog') and toot.reblog:
|
|
||||||
print('👎 unboosting toot ' + str(toot.id) + ' boosted ' + toot.created_at.strftime("%d %b %Y"))
|
|
||||||
deleted_count += 1
|
|
||||||
# unreblog the original toot (their toot), not the toot created by boosting (your toot)
|
|
||||||
mastodon.status_unreblog(toot.reblog)
|
|
||||||
else:
|
|
||||||
print('❌ deleting toot ' + str(toot.id) + ' tooted ' + toot.created_at.strftime("%d %b %Y"))
|
|
||||||
deleted_count += 1
|
|
||||||
mastodon.status_delete(toot)
|
|
||||||
except:
|
|
||||||
print('🛑 **error** with toot - ' + str(toot.id))
|
|
||||||
|
|
||||||
# the account_statuses call is paginated with a 40-toot limit
|
def checkToots(timeline, deleted_count=0):
|
||||||
# get the id of the last toot to include as 'max_id' in the next API call.
|
for toot in timeline:
|
||||||
# then keep triggering new rounds of checkToots() until there are no more toots to check
|
try:
|
||||||
try:
|
if config.save_pinned and hasattr(toot, "pinned") and toot.pinned:
|
||||||
max_id = timeline[-1:][0].id
|
print("📌 skipping pinned toot - " + str(toot.id))
|
||||||
next_batch = mastodon.account_statuses(user_id, limit=40, max_id=max_id)
|
elif toot.id in config.toots_to_save:
|
||||||
if len(next_batch) > 0:
|
print("💾 skipping saved toot - " + str(toot.id))
|
||||||
checkToots(next_batch, deleted_count)
|
elif cutoff_date > toot.created_at:
|
||||||
else:
|
if hasattr(toot, "reblog") and toot.reblog:
|
||||||
print('Removed ' + str(deleted_count) + ' toots.')
|
print(
|
||||||
except IndexError:
|
"👎 unboosting toot "
|
||||||
print('No toots found!')
|
+ str(toot.id)
|
||||||
|
+ " boosted "
|
||||||
|
+ toot.created_at.strftime("%d %b %Y")
|
||||||
|
)
|
||||||
|
deleted_count += 1
|
||||||
|
# unreblog the original toot (their toot), not the toot created by boosting (your toot)
|
||||||
|
mastodon.status_unreblog(toot.reblog)
|
||||||
|
else:
|
||||||
|
print(
|
||||||
|
"❌ deleting toot "
|
||||||
|
+ str(toot.id)
|
||||||
|
+ " tooted "
|
||||||
|
+ toot.created_at.strftime("%d %b %Y")
|
||||||
|
)
|
||||||
|
deleted_count += 1
|
||||||
|
mastodon.status_delete(toot)
|
||||||
|
except:
|
||||||
|
print("🛑 **error** with toot - " + str(toot.id))
|
||||||
|
|
||||||
|
# the account_statuses call is paginated with a 40-toot limit
|
||||||
|
# get the id of the last toot to include as 'max_id' in the next API call.
|
||||||
|
# then keep triggering new rounds of checkToots() until there are no more toots to check
|
||||||
|
try:
|
||||||
|
max_id = timeline[-1:][0].id
|
||||||
|
next_batch = mastodon.account_statuses(user_id, limit=40, max_id=max_id)
|
||||||
|
if len(next_batch) > 0:
|
||||||
|
checkToots(next_batch, deleted_count)
|
||||||
|
else:
|
||||||
|
print("Removed " + str(deleted_count) + " toots.")
|
||||||
|
except IndexError:
|
||||||
|
print("No toots found!")
|
||||||
|
|
||||||
|
|
||||||
# trigger from here
|
# trigger from here
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
account = mastodon.account(user_id)
|
account = mastodon.account(user_id)
|
||||||
print('Checking ' + str(account.statuses_count) + ' toots...')
|
print("Checking " + str(account.statuses_count) + " toots...")
|
||||||
checkToots(timeline)
|
checkToots(timeline)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user