1
0
mirror of https://github.com/hughrun/ephemetoot synced 2025-03-03 18:58:10 +01:00

add --quiet mode

This new option suppresses most logging, except for very basic information (which account is being worked on, and how many toots were deleted).

Exception messages are not suppressed.
This commit is contained in:
Hugh Rundle 2020-07-18 18:02:30 +10:00
parent f5016fe684
commit 62db64a73f
2 changed files with 57 additions and 49 deletions

View File

@ -54,6 +54,9 @@ parser.add_argument(
parser.add_argument( parser.add_argument(
"--pace", action="store_true", help="Slow deletion actions to match API rate limit to avoid pausing" "--pace", action="store_true", help="Slow deletion actions to match API rate limit to avoid pausing"
) )
parser.add_argument(
"--quiet", action="store_true", help="Suppress most logging"
)
parser.add_argument( parser.add_argument(
"--schedule", action="store", metavar="filepath", nargs="?", const=".", help="Save and load plist file on MacOS" "--schedule", action="store", metavar="filepath", nargs="?", const=".", help="Save and load plist file on MacOS"
) )
@ -81,6 +84,7 @@ if __name__ == "__main__":
elif options.schedule: elif options.schedule:
ephemetoot.schedule(options) ephemetoot.schedule(options)
else: else:
if not options.quiet:
print('') print('')
print('============= EPHEMETOOT v' + vnum + ' ================') print('============= EPHEMETOOT v' + vnum + ' ================')
print('Running at ' + str( datetime.now(timezone.utc).strftime('%a %d %b %Y %H:%M:%S %z') )) print('Running at ' + str( datetime.now(timezone.utc).strftime('%a %d %b %Y %H:%M:%S %z') ))

View File

@ -130,7 +130,7 @@ def checkToots(config, options, retry_count=0):
toot_tags.add(tag.name) toot_tags.add(tag.name)
try: try:
if keep_pinned and hasattr(toot, "pinned") and toot.pinned: if keep_pinned and hasattr(toot, "pinned") and toot.pinned:
if not options.hide_skipped: if not (options.hide_skipped or options.quiet):
if options.datestamp: if options.datestamp:
print( print(
str( str(
@ -143,7 +143,7 @@ def checkToots(config, options, retry_count=0):
print("📌 skipping pinned toot - " + str(toot.id)) print("📌 skipping pinned toot - " + str(toot.id))
elif toot.id in toots_to_keep: elif toot.id in toots_to_keep:
if not options.hide_skipped: if not (options.hide_skipped or options.quiet):
if options.datestamp: if options.datestamp:
print( print(
str( str(
@ -156,7 +156,7 @@ def checkToots(config, options, retry_count=0):
print("💾 skipping saved toot - " + str(toot.id)) print("💾 skipping saved toot - " + str(toot.id))
elif toot.visibility in visibility_to_keep: elif toot.visibility in visibility_to_keep:
if not options.hide_skipped: if not (options.hide_skipped or options.quiet):
if options.datestamp: if options.datestamp:
print( print(
str( str(
@ -174,7 +174,7 @@ def checkToots(config, options, retry_count=0):
+ str(toot.id) + str(toot.id)
) )
elif len(hashtags_to_keep.intersection(toot_tags)) > 0: elif len(hashtags_to_keep.intersection(toot_tags)) > 0:
if not options.hide_skipped: if not (options.hide_skipped or options.quiet):
if options.datestamp: if options.datestamp:
print( print(
str( str(
@ -188,6 +188,7 @@ def checkToots(config, options, retry_count=0):
print("#️⃣ skipping toot with hashtag - " + str(toot.id)) print("#️⃣ skipping toot with hashtag - " + str(toot.id))
elif cutoff_date > toot.created_at: elif cutoff_date > toot.created_at:
if hasattr(toot, "reblog") and toot.reblog: if hasattr(toot, "reblog") and toot.reblog:
if not options.quiet:
if options.datestamp: if options.datestamp:
print( print(
str( str(
@ -208,6 +209,7 @@ def checkToots(config, options, retry_count=0):
# unreblog the original toot (their toot), not the toot created by boosting (your toot) # unreblog the original toot (their toot), not the toot created by boosting (your toot)
if not options.test: if not options.test:
if mastodon.ratelimit_remaining == 0: if mastodon.ratelimit_remaining == 0:
if not options.quiet:
print( print(
"Rate limit reached. Waiting for a rate limit reset" "Rate limit reached. Waiting for a rate limit reset"
) )
@ -219,6 +221,7 @@ def checkToots(config, options, retry_count=0):
f.close() f.close()
mastodon.status_unreblog(toot.reblog) mastodon.status_unreblog(toot.reblog)
else: else:
if not options.quiet:
if options.datestamp: if options.datestamp:
print( print(
str( str(
@ -240,7 +243,7 @@ def checkToots(config, options, retry_count=0):
2 2
) # wait 2 secs between deletes to be a bit nicer to the server ) # wait 2 secs between deletes to be a bit nicer to the server
if not options.test: if not options.test:
if mastodon.ratelimit_remaining == 0: if mastodon.ratelimit_remaining == 0 and not options.quiet:
now = time.time() now = time.time()
diff = mastodon.ratelimit_reset - now diff = mastodon.ratelimit_reset - now
@ -358,8 +361,8 @@ def checkToots(config, options, retry_count=0):
print("Removed " + str(deleted_count) + " toots.") print("Removed " + str(deleted_count) + " toots.")
print("") if not options.quiet:
print("---------------------------------------") print("\n---------------------------------------")
print("🥳 ==> 🧼 ==> 😇 User cleanup complete!") print("🥳 ==> 🧼 ==> 😇 User cleanup complete!")
print("---------------------------------------\n") print("---------------------------------------\n")
@ -386,6 +389,7 @@ def checkToots(config, options, retry_count=0):
account = mastodon.account(user_id) account = mastodon.account(user_id)
timeline = mastodon.account_statuses(user_id, limit=40) timeline = mastodon.account_statuses(user_id, limit=40)
if not options.quiet:
print("Checking " + str(account.statuses_count) + " toots") print("Checking " + str(account.statuses_count) + " toots")
checkBatch(timeline) checkBatch(timeline)