refactor print statements

This commit is contained in:
Hugh Rundle 2020-08-30 14:33:36 +10:00
parent 619a4a42f7
commit f6542f0529
1 changed files with 72 additions and 101 deletions

View File

@ -134,16 +134,17 @@ def version(vnum):
''' '''
Prints current and latest version numbers to console. Prints current and latest version numbers to console.
''' '''
try: try:
latest = requests.get( latest = requests.get(
"https://api.github.com/repos/hughrun/ephemetoot/releases/latest" "https://api.github.com/repos/hughrun/ephemetoot/releases/latest"
) )
res = latest.json() res = latest.json()
latest_version = res["name"] latest_version = res["tag_name"]
print("\nephemetoot ==> 🥳 ==> 🧼 ==> 😇") print("\nephemetoot ==> 🥳 ==> 🧼 ==> 😇")
print("-------------------------------") print("-------------------------------")
print("Using: \033[92mVersion " + vnum + "\033[0m") print("You are using release: \033[92mv", vnum, "\033[0m", sep="")
print("Latest: \033[92m" + latest_version + "\033[0m") print("The latest release is: \033[92m" + latest_version + "\033[0m")
print( print(
"To upgrade to the most recent version run \033[92mpip3 install --update ephemetoot\033[0m" "To upgrade to the most recent version run \033[92mpip3 install --update ephemetoot\033[0m"
) )
@ -204,6 +205,26 @@ def schedule(options):
except Exception as e: except Exception as e:
print("🙁 Scheduling failed.") print("🙁 Scheduling failed.")
# TODO: move the json function to here and understand what it does
def archive_toot():
pass
# TODO: move all the archiving logic and definitions to here
def tooted_time(toot):
# TODO: return a string with the toot created time
pass
def datestamp_now():
return str(
datetime.now(timezone.utc).strftime(
"%a %d %b %Y %H:%M:%S %z"
)
)
# TODO: move this out of checkToots and pass through all needed arg
# def checkBatch():
# pass
def checkToots(config, options, retry_count=0): def checkToots(config, options, retry_count=0):
@ -261,88 +282,65 @@ def checkToots(config, options, retry_count=0):
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 or options.quiet): if not (options.hide_skipped or options.quiet):
if options.datestamp:
print(
str(
datetime.now(timezone.utc).strftime(
"%a %d %b %Y %H:%M:%S %z"
)
),
end=" : ",
)
print("📌 skipping pinned toot - " + str(toot.id)) if options.datestamp:
print(datestamp_now(),end=" : ")
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 or options.quiet): if not (options.hide_skipped or options.quiet):
if options.datestamp:
print(
str(
datetime.now(timezone.utc).strftime(
"%a %d %b %Y %H:%M:%S %z"
)
),
end=" : ",
)
print("💾 skipping saved toot - " + str(toot.id)) if options.datestamp:
print(datestamp_now(),end=" : ")
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 or options.quiet): if not (options.hide_skipped or options.quiet):
if options.datestamp: if options.datestamp:
print( print(datestamp_now(), end=" : ")
str(
datetime.now(timezone.utc).strftime(
"%a %d %b %Y %H:%M:%S %z"
)
),
end=" : ",
)
print( print(
"👀 skipping " "👀 skipping",
+ toot.visibility toot.visibility,
+ " toot - " "toot -",
+ 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 or options.quiet): if not (options.hide_skipped or options.quiet):
if options.datestamp:
print(
str(
datetime.now(timezone.utc).strftime(
"%a %d %b %Y %H:%M:%S %z"
)
),
end=" : ",
)
print("#️⃣ skipping toot with hashtag - " + str(toot.id)) if options.datestamp:
print(datestamp_now(), end=" : ")
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 not options.quiet:
if options.datestamp: if options.datestamp:
print( print(datestamp_now(), end=" : ")
str(
datetime.now(timezone.utc).strftime(
"%a %d %b %Y %H:%M:%S %z"
)
),
end=" : ",
)
print( print(
"👎 unboosting toot " "👎 unboosting toot",
+ str(toot.id) str(toot.id),
+ " boosted " "boosted",
+ toot.created_at.strftime("%d %b %Y") toot.created_at.strftime("%d %b %Y")
) )
deleted_count += 1 deleted_count += 1
# 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: if not options.quiet:
print( print("Rate limit reached. Waiting for a rate limit reset")
"Rate limit reached. Waiting for a rate limit reset"
)
# check for --archive-deleted # check for --archive-deleted
if ( if (
options.archive_deleted options.archive_deleted
@ -361,21 +359,14 @@ def checkToots(config, options, retry_count=0):
else: else:
if not options.quiet: if not options.quiet:
if options.datestamp: if options.datestamp:
print( print(datestamp_now(), end=" : ")
str(
datetime.now(timezone.utc).strftime(
"%a %d %b %Y %H:%M:%S %z"
)
),
end=" : ",
)
print( print(
"❌ deleting toot " "❌ deleting toot",
+ str(toot.id) str(toot.id), "tooted",
+ " tooted " toot.created_at.strftime("%d %b %Y")
+ toot.created_at.strftime("%d %b %Y")
) )
deleted_count += 1 deleted_count += 1
time.sleep( time.sleep(
2 2
@ -390,15 +381,11 @@ def checkToots(config, options, retry_count=0):
diff = mastodon.ratelimit_reset - now diff = mastodon.ratelimit_reset - now
print( print(
"\nRate limit reached at " "\nRate limit reached at",
+ str( datestamp_now(),
datetime.now(timezone.utc).strftime( "- next reset due in",
"%a %d %b %Y %H:%M:%S %z" str(format(diff / 60, ".0f")),
) "minutes.\n"
)
+ " - next reset due in "
+ str(format(diff / 60, ".0f"))
+ " minutes.\n"
) )
# check for --archive-deleted # check for --archive-deleted
if ( if (
@ -424,11 +411,7 @@ def checkToots(config, options, retry_count=0):
print( print(
"\nRate limit reached at " "\nRate limit reached at "
+ str( + datestamp_now()
datetime.now(timezone.utc).strftime(
"%a %d %b %Y %H:%M:%S %z"
)
)
+ " - waiting for next reset due in " + " - waiting for next reset due in "
+ str(format(diff / 60, ".0f")) + str(format(diff / 60, ".0f"))
+ " minutes.\n" + " minutes.\n"
@ -447,11 +430,7 @@ def checkToots(config, options, retry_count=0):
"Attempt " "Attempt "
+ str(attempts) + str(attempts)
+ " at " + " at "
+ str( + datestamp_now()
datetime.now(timezone.utc).strftime(
"%a %d %b %Y %H:%M:%S %z"
)
)
) )
mastodon.status_delete(toot) mastodon.status_delete(toot)
time.sleep( time.sleep(
@ -511,11 +490,7 @@ def checkToots(config, options, retry_count=0):
if options.datestamp: if options.datestamp:
print( print(
"\n\n" "\n\n"
+ str( + datestamp_now(),
datetime.now(timezone.utc).strftime(
"%a %d %b %Y %H:%M:%S %z"
)
),
end=" : ", end=" : ",
) )
@ -528,11 +503,7 @@ def checkToots(config, options, retry_count=0):
if options.datestamp: if options.datestamp:
print( print(
"\n\n" "\n\n"
+ str( + datestamp_now(),
datetime.now(timezone.utc).strftime(
"%a %d %b %Y %H:%M:%S %z"
)
),
end=" : ", end=" : ",
) )