resolve #23 include datestamp option for all actions

This commit is contained in:
Hugh Rundle 2020-06-20 20:52:34 +10:00
parent 898ce41fb7
commit 669d276f81
3 changed files with 36 additions and 8 deletions

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
config.py
config.yaml
config.yaml
_assets

View File

@ -28,7 +28,7 @@ import yaml
# from standard library
from argparse import ArgumentParser
from datetime import datetime
from datetime import datetime, timezone
import os
# local files
@ -39,11 +39,14 @@ parser.add_argument(
"--config", action="store", metavar="'filepath'", default="config.yaml", help="filepath of your config file, relative to the current directory. If no --config path is provided, ephemetoot will use 'config.yaml'."
)
parser.add_argument(
"--test", action="store_true", help="do a test run without deleting any toots"
"--datestamp", action="store_true", help="include a datetime stamp for every action (e.g. deleting a toot)"
)
parser.add_argument(
"--schedule", action="store", metavar="'filepath'", nargs="?", const=".", help="save and load plist file on MacOS"
)
parser.add_argument(
"--test", action="store_true", help="do a test run without deleting any toots"
)
parser.add_argument(
"--time", action="store", metavar="'hours minutes'", nargs="*", help="hour and minute to schedule: e.g. 9 30 for 9.30am"
)
@ -61,9 +64,9 @@ if __name__ == "__main__":
ephemetoot.schedule(options)
else:
print('')
print('=========== EPHEMETOOT ================')
print('Running at ' + str(datetime.now() ))
print('=======================================')
print('============= EPHEMETOOT ================')
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...")

View File

@ -69,16 +69,25 @@ def checkToots(config, options, retry_count=0):
toot_tags.add(tag.name)
try:
if keep_pinned and hasattr(toot, "pinned") and toot.pinned:
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)
)
elif toot.id in toots_to_keep:
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)
)
elif toot.visibility in visibility_to_keep:
if options.datestamp:
print(str( datetime.now(timezone.utc).strftime('%a %d %b %Y %H:%M:%S %z') ), end=' : ')
print(
"👀 skipping "
+ toot.visibility
@ -86,12 +95,18 @@ def checkToots(config, options, retry_count=0):
+ str(toot.id)
)
elif len(hashtags_to_keep.intersection(toot_tags)) > 0:
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)
)
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=' : ')
print(
"👎 unboosting toot "
+ str(toot.id)
@ -107,6 +122,9 @@ def checkToots(config, options, retry_count=0):
)
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=' : ')
print(
"❌ deleting toot "
+ str(toot.id)
@ -180,12 +198,18 @@ def checkToots(config, options, retry_count=0):
checkBatch(next_batch, deleted_count)
else:
if options.test:
if options.datestamp:
print('\n\n' + str( datetime.now(timezone.utc).strftime('%a %d %b %Y %H:%M:%S %z') ), end=' : ')
print(
"\nTest run completed. This would have removed "
"Test run completed. This would have removed "
+ str(deleted_count)
+ " toots."
)
else:
if options.datestamp:
print('\n\n' + str( datetime.now(timezone.utc).strftime('%a %d %b %Y %H:%M:%S %z') ), end=' : ')
print(
"Removed "
+ str(deleted_count)
@ -195,7 +219,7 @@ def checkToots(config, options, retry_count=0):
print('')
print('---------------------------------------')
print('🥳 ==> 🧼 ==> 😇 User cleanup complete!')
print('---------------------------------------')
print('---------------------------------------\n')
except IndexError:
print("No toots found!")