1
0
mirror of https://github.com/hughrun/ephemetoot synced 2025-01-10 13:02:36 +01:00

add the ability to do a test run

This commit is contained in:
Mark Eaton 2019-02-13 23:22:35 -05:00
parent 6082441e9e
commit a3b9fa6b56

View File

@ -22,11 +22,20 @@
# or email hugh [at] hughrundle [dot] net # or email hugh [at] hughrundle [dot] net
# ##################################################################### # #####################################################################
from argparse import ArgumentParser
import config import config
import json import json
from mastodon import Mastodon from mastodon import Mastodon
from datetime import datetime, timedelta, timezone from datetime import datetime, timedelta, timezone
parser = ArgumentParser()
parser.add_argument(
"--test", action="store_true", help="do a test run without deleting any toots"
)
options = parser.parse_args()
if options.test:
print("This is a test run...")
print("Fetching account details...") print("Fetching account details...")
mastodon = Mastodon(access_token=config.access_token, api_base_url=config.base_url) mastodon = Mastodon(access_token=config.access_token, api_base_url=config.base_url)
@ -62,6 +71,7 @@ def checkToots(timeline, deleted_count=0):
+ toot.created_at.strftime("%d %b %Y") + toot.created_at.strftime("%d %b %Y")
) )
deleted_count += 1 deleted_count += 1
if not options.test:
mastodon.status_delete(toot) mastodon.status_delete(toot)
except: except:
print("🛑 **error** with toot - " + str(toot.id)) print("🛑 **error** with toot - " + str(toot.id))
@ -74,6 +84,13 @@ def checkToots(timeline, deleted_count=0):
next_batch = mastodon.account_statuses(user_id, limit=40, max_id=max_id) next_batch = mastodon.account_statuses(user_id, limit=40, max_id=max_id)
if len(next_batch) > 0: if len(next_batch) > 0:
checkToots(next_batch, deleted_count) checkToots(next_batch, deleted_count)
else:
if options.test:
print(
"Test run. This would have removed "
+ str(deleted_count)
+ " toots."
)
else: else:
print("Removed " + str(deleted_count) + " toots.") print("Removed " + str(deleted_count) + " toots.")
except IndexError: except IndexError: