commit
94ac7869d1
|
@ -101,6 +101,11 @@ parser.add_argument(
|
||||||
nargs="*",
|
nargs="*",
|
||||||
help="Hour and minute to schedule: e.g. 9 30 for 9.30am",
|
help="Hour and minute to schedule: e.g. 9 30 for 9.30am",
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--verbose",
|
||||||
|
action="store_true",
|
||||||
|
help="Log more information about errors and exceptions",
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--version",
|
"--version",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
|
|
|
@ -129,8 +129,7 @@ def version(vnum):
|
||||||
)
|
)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Something went wrong:")
|
print("Something went wrong:", e)
|
||||||
|
|
||||||
|
|
||||||
def schedule(options):
|
def schedule(options):
|
||||||
|
|
||||||
|
@ -185,6 +184,8 @@ def schedule(options):
|
||||||
print("⏰ Scheduled!")
|
print("⏰ Scheduled!")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("🙁 Scheduling failed.", e)
|
print("🙁 Scheduling failed.", e)
|
||||||
|
if options.verbose:
|
||||||
|
print(e)
|
||||||
|
|
||||||
def archive_toot(config, toot):
|
def archive_toot(config, toot):
|
||||||
# define archive path
|
# define archive path
|
||||||
|
@ -365,9 +366,15 @@ def process_toot(config, options, mastodon, deleted_count, toot):
|
||||||
print_rate_limit_message(mastodon)
|
print_rate_limit_message(mastodon)
|
||||||
time.sleep(diff + 1) # wait for rate limit to reset
|
time.sleep(diff + 1) # wait for rate limit to reset
|
||||||
|
|
||||||
|
# If a server goes offline for maintenance etc halfway through a run, we don't necessarily
|
||||||
|
# want to just error out. Handling it here allows us to give it time to sort itself out.
|
||||||
except MastodonError as e:
|
except MastodonError as e:
|
||||||
|
|
||||||
|
if options.verbose:
|
||||||
|
print("🛑 ERROR deleting toot -", str(toot.id), "\n", e)
|
||||||
|
else:
|
||||||
print( "🛑 ERROR deleting toot -", str(toot.id), "-", str(e.args[0]), "-", str(e.args[3]) )
|
print( "🛑 ERROR deleting toot -", str(toot.id), "-", str(e.args[0]), "-", str(e.args[3]) )
|
||||||
|
|
||||||
console_print(
|
console_print(
|
||||||
"Waiting " + str(options.retry_mins) + " minutes before re-trying",
|
"Waiting " + str(options.retry_mins) + " minutes before re-trying",
|
||||||
options,
|
options,
|
||||||
|
@ -376,22 +383,6 @@ def process_toot(config, options, mastodon, deleted_count, toot):
|
||||||
time.sleep(60 * options.retry_mins)
|
time.sleep(60 * options.retry_mins)
|
||||||
retry_on_error(options, mastodon, toot, attempts=2)
|
retry_on_error(options, mastodon, toot, attempts=2)
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
print("Operation aborted.")
|
|
||||||
|
|
||||||
except KeyError as e:
|
|
||||||
print(
|
|
||||||
"⚠️ There is an error in your config.yaml file. Please add a value for",
|
|
||||||
str(e),
|
|
||||||
"and try again."
|
|
||||||
)
|
|
||||||
|
|
||||||
except:
|
|
||||||
e = sys.exc_info()
|
|
||||||
print( "🛑 Unknown ERROR deleting toot -", str(toot.id) )
|
|
||||||
print( "ERROR:", str(e[0]),"-", str(e[1]) )
|
|
||||||
|
|
||||||
|
|
||||||
def check_batch(config, options, mastodon, user_id, timeline, deleted_count=0):
|
def check_batch(config, options, mastodon, user_id, timeline, deleted_count=0):
|
||||||
"""
|
"""
|
||||||
Check a batch of up to 40 toots. This is usually triggered by check_toots, and then recursively calls itself until all toots within the time period specified have been checked.
|
Check a batch of up to 40 toots. This is usually triggered by check_toots, and then recursively calls itself until all toots within the time period specified have been checked.
|
||||||
|
@ -410,13 +401,7 @@ def check_batch(config, options, mastodon, user_id, timeline, deleted_count=0):
|
||||||
if len(next_batch) > 0:
|
if len(next_batch) > 0:
|
||||||
check_batch(config, options, mastodon, user_id, next_batch, deleted_count)
|
check_batch(config, options, mastodon, user_id, next_batch, deleted_count)
|
||||||
else:
|
else:
|
||||||
if options.test:
|
if not options.test:
|
||||||
if options.datestamp:
|
|
||||||
print( "\n", datestamp_now(), sep="", end=" : ")
|
|
||||||
|
|
||||||
print(
|
|
||||||
"Test run completed. This would have removed", str(deleted_count), "toots.\n")
|
|
||||||
else:
|
|
||||||
if options.datestamp:
|
if options.datestamp:
|
||||||
print( "\n", datestamp_now(), end=" : ")
|
print( "\n", datestamp_now(), end=" : ")
|
||||||
|
|
||||||
|
@ -427,12 +412,23 @@ def check_batch(config, options, mastodon, user_id, timeline, deleted_count=0):
|
||||||
print("🥳 ==> 🧼 ==> 😇 User cleanup complete!")
|
print("🥳 ==> 🧼 ==> 😇 User cleanup complete!")
|
||||||
print("---------------------------------------\n")
|
print("---------------------------------------\n")
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
|
if options.quiet:
|
||||||
|
if options.datestamp:
|
||||||
|
print( "\n", datestamp_now(), sep="", end=" : ")
|
||||||
|
|
||||||
|
print("Test run completed. This would have removed", str(deleted_count), "toots.\n")
|
||||||
|
|
||||||
|
else:
|
||||||
|
print("---------------------------------------")
|
||||||
|
print("🥳 ==> 🧪 ==> 📋 Test run complete!")
|
||||||
|
print("This would have removed", str(deleted_count), "toots.")
|
||||||
|
print("---------------------------------------\n")
|
||||||
|
|
||||||
except IndexError:
|
except IndexError:
|
||||||
print("No toots found!\n")
|
print("No toots found!\n")
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print("ERROR:", str(e.args[0]), "\n")
|
|
||||||
|
|
||||||
def check_toots(config, options, retry_count=0):
|
def check_toots(config, options, retry_count=0):
|
||||||
'''
|
'''
|
||||||
The main function, uses the Mastodon API to check all toots in the user timeline, and delete any that do not meet any of the exclusion criteria from the config file.
|
The main function, uses the Mastodon API to check all toots in the user timeline, and delete any that do not meet any of the exclusion criteria from the config file.
|
||||||
|
@ -464,6 +460,9 @@ def check_toots(config, options, retry_count=0):
|
||||||
# check_batch() then recursively keeps looping until all toots have been checked
|
# check_batch() then recursively keeps looping until all toots have been checked
|
||||||
check_batch(config, options, mastodon, user_id, timeline)
|
check_batch(config, options, mastodon, user_id, timeline)
|
||||||
|
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("Operation aborted.")
|
||||||
|
|
||||||
except KeyError as val:
|
except KeyError as val:
|
||||||
print("\n⚠️ error with in your config.yaml file!")
|
print("\n⚠️ error with in your config.yaml file!")
|
||||||
print("Please ensure there is a value for " + str(val) + "\n")
|
print("Please ensure there is a value for " + str(val) + "\n")
|
||||||
|
@ -478,9 +477,14 @@ def check_toots(config, options, retry_count=0):
|
||||||
else:
|
else:
|
||||||
print("\n😕 Server has returned an error (5xx)\n")
|
print("\n😕 Server has returned an error (5xx)\n")
|
||||||
|
|
||||||
except MastodonNetworkError:
|
if options.verbose:
|
||||||
|
print(e, "\n")
|
||||||
|
|
||||||
|
except MastodonNetworkError as e:
|
||||||
if retry_count == 0:
|
if retry_count == 0:
|
||||||
print("\n📡 ephemetoot cannot connect to the server - are you online?")
|
print("\n📡 ephemetoot cannot connect to the server - are you online?")
|
||||||
|
if options.verbose:
|
||||||
|
print(e)
|
||||||
if retry_count < 4:
|
if retry_count < 4:
|
||||||
print("Waiting " + str(options.retry_mins) + " minutes before trying again")
|
print("Waiting " + str(options.retry_mins) + " minutes before trying again")
|
||||||
time.sleep(60 * options.retry_mins)
|
time.sleep(60 * options.retry_mins)
|
||||||
|
@ -489,3 +493,9 @@ def check_toots(config, options, retry_count=0):
|
||||||
check_toots(config, options, retry_count)
|
check_toots(config, options, retry_count)
|
||||||
else:
|
else:
|
||||||
print("Gave up waiting for network\n")
|
print("Gave up waiting for network\n")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
if options.verbose:
|
||||||
|
print("ERROR:", e)
|
||||||
|
else:
|
||||||
|
print("ERROR:", str(e.args[0]), "\n")
|
Loading…
Reference in New Issue