Merge pull request #3 from MarkEEaton/test-run-argparse

add test run functionality
This commit is contained in:
Hugh Rundle 2019-03-08 15:49:31 +11:00 committed by GitHub
commit eb0d055275
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 3 deletions

View File

@ -22,11 +22,20 @@
# or email hugh [at] hughrundle [dot] net
# #####################################################################
from argparse import ArgumentParser
import config
import json
from mastodon import Mastodon
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...")
mastodon = Mastodon(access_token=config.access_token, api_base_url=config.base_url)
@ -53,6 +62,7 @@ def checkToots(timeline, deleted_count=0):
)
deleted_count += 1
# unreblog the original toot (their toot), not the toot created by boosting (your toot)
if not options.test:
mastodon.status_unreblog(toot.reblog)
else:
print(
@ -62,6 +72,7 @@ def checkToots(timeline, deleted_count=0):
+ toot.created_at.strftime("%d %b %Y")
)
deleted_count += 1
if not options.test:
mastodon.status_delete(toot)
except:
print("🛑 **error** with toot - " + str(toot.id))
@ -74,6 +85,13 @@ def checkToots(timeline, deleted_count=0):
next_batch = mastodon.account_statuses(user_id, limit=40, max_id=max_id)
if len(next_batch) > 0:
checkToots(next_batch, deleted_count)
else:
if options.test:
print(
"Test run. This would have removed "
+ str(deleted_count)
+ " toots."
)
else:
print("Removed " + str(deleted_count) + " toots.")
except IndexError: