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(
"--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(
"--schedule", action="store", metavar="filepath", nargs="?", const=".", help="Save and load plist file on MacOS"
)
@ -81,11 +84,12 @@ if __name__ == "__main__":
elif options.schedule:
ephemetoot.schedule(options)
else:
print('')
print('============= EPHEMETOOT v' + vnum + ' ================')
print('Running at ' + str( datetime.now(timezone.utc).strftime('%a %d %b %Y %H:%M:%S %z') ))
print('================================================')
print('')
if not options.quiet:
print('')
print('============= EPHEMETOOT v' + vnum + ' ================')
print('Running at ' + str( datetime.now(timezone.utc).strftime('%a %d %b %Y %H:%M:%S %z') ))
print('================================================')
print('')
if options.test:
print("This is a test run...\n")
with open(config_file) as config:

View File

@ -130,7 +130,7 @@ def checkToots(config, options, retry_count=0):
toot_tags.add(tag.name)
try:
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:
print(
str(
@ -143,7 +143,7 @@ def checkToots(config, options, retry_count=0):
print("📌 skipping pinned toot - " + str(toot.id))
elif toot.id in toots_to_keep:
if not options.hide_skipped:
if not (options.hide_skipped or options.quiet):
if options.datestamp:
print(
str(
@ -156,7 +156,7 @@ def checkToots(config, options, retry_count=0):
print("💾 skipping saved toot - " + str(toot.id))
elif toot.visibility in visibility_to_keep:
if not options.hide_skipped:
if not (options.hide_skipped or options.quiet):
if options.datestamp:
print(
str(
@ -174,7 +174,7 @@ def checkToots(config, options, retry_count=0):
+ str(toot.id)
)
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:
print(
str(
@ -188,29 +188,31 @@ def checkToots(config, options, retry_count=0):
print("#️⃣ skipping toot with hashtag - " + str(toot.id))
elif cutoff_date > toot.created_at:
if hasattr(toot, "reblog") and toot.reblog:
if options.datestamp:
print(
str(
datetime.now(timezone.utc).strftime(
"%a %d %b %Y %H:%M:%S %z"
)
),
end=" : ",
)
if not options.quiet:
if options.datestamp:
print(
str(
datetime.now(timezone.utc).strftime(
"%a %d %b %Y %H:%M:%S %z"
)
),
end=" : ",
)
print(
"👎 unboosting toot "
+ str(toot.id)
+ " boosted "
+ toot.created_at.strftime("%d %b %Y")
)
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)
if not options.test:
if mastodon.ratelimit_remaining == 0:
print(
"Rate limit reached. Waiting for a rate limit reset"
)
if not options.quiet:
print(
"Rate limit reached. Waiting for a rate limit reset"
)
# check for --archive-deleted
if options.archive_deleted and "id" in toot and "archive" in config:
# write toot to archive
@ -219,28 +221,29 @@ def checkToots(config, options, retry_count=0):
f.close()
mastodon.status_unreblog(toot.reblog)
else:
if options.datestamp:
print(
str(
datetime.now(timezone.utc).strftime(
"%a %d %b %Y %H:%M:%S %z"
)
),
end=" : ",
)
if not options.quiet:
if options.datestamp:
print(
str(
datetime.now(timezone.utc).strftime(
"%a %d %b %Y %H:%M:%S %z"
)
),
end=" : ",
)
print(
"❌ deleting toot "
+ str(toot.id)
+ " tooted "
+ toot.created_at.strftime("%d %b %Y")
)
print(
"❌ deleting toot "
+ str(toot.id)
+ " tooted "
+ toot.created_at.strftime("%d %b %Y")
)
deleted_count += 1
time.sleep(
2
) # wait 2 secs between deletes to be a bit nicer to the server
if not options.test:
if mastodon.ratelimit_remaining == 0:
if mastodon.ratelimit_remaining == 0 and not options.quiet:
now = time.time()
diff = mastodon.ratelimit_reset - now
@ -262,7 +265,7 @@ def checkToots(config, options, retry_count=0):
with open(filename, "w") as f:
f.write(json.dumps(toot, indent=4, default=jsondefault))
f.close()
mastodon.status_delete(toot)
except MastodonRatelimitError:
@ -358,10 +361,10 @@ def checkToots(config, options, retry_count=0):
print("Removed " + str(deleted_count) + " toots.")
print("")
print("---------------------------------------")
print("🥳 ==> 🧼 ==> 😇 User cleanup complete!")
print("---------------------------------------\n")
if not options.quiet:
print("\n---------------------------------------")
print("🥳 ==> 🧼 ==> 😇 User cleanup complete!")
print("---------------------------------------\n")
except IndexError:
print("No toots found!")
@ -386,7 +389,8 @@ def checkToots(config, options, retry_count=0):
account = mastodon.account(user_id)
timeline = mastodon.account_statuses(user_id, limit=40)
print("Checking " + str(account.statuses_count) + " toots")
if not options.quiet:
print("Checking " + str(account.statuses_count) + " toots")
checkBatch(timeline)