mirror of
https://github.com/hughrun/ephemetoot
synced 2025-02-28 09:17:57 +01:00
add --archive-deleted flag
This adds a flag to restrict the archive to only toots about to be deleted, rather than archiving everything.
This commit is contained in:
parent
7aa2b89424
commit
f5016fe684
@ -39,6 +39,9 @@ from lib import ephemetoot
|
||||
vnum = pkg_resources.require("ephemetoot")[0].version
|
||||
|
||||
parser = ArgumentParser()
|
||||
parser.add_argument(
|
||||
"--archive-deleted", action="store_true", help="Only archive toots that are being deleted"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--config", action="store", metavar="filepath", default="config.yaml", help="Filepath of your config file, absolute or relative to the current directory. If no --config path is provided, ephemetoot will use 'config.yaml'."
|
||||
)
|
||||
@ -46,7 +49,7 @@ parser.add_argument(
|
||||
"--datestamp", action="store_true", help="Include a datetime stamp for every action (e.g. deleting a toot)"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--hide_skipped", action="store_true", help="Do not write to log when skipping saved toots"
|
||||
"--hide-skipped", "--hide_skipped", action="store_true", help="Do not write to log when skipping saved toots"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--pace", action="store_true", help="Slow deletion actions to match API rate limit to avoid pausing"
|
||||
@ -84,8 +87,7 @@ if __name__ == "__main__":
|
||||
print('================================================')
|
||||
print('')
|
||||
if options.test:
|
||||
print("This is a test run...")
|
||||
print('')
|
||||
print("This is a test run...\n")
|
||||
with open(config_file) as config:
|
||||
for accounts in yaml.safe_load_all(config):
|
||||
for user in accounts:
|
||||
|
@ -116,13 +116,14 @@ def checkToots(config, options, retry_count=0):
|
||||
archive_path = os.path.join( os.getcwd(), config["archive"] )
|
||||
if archive_path[-1] != '/':
|
||||
archive_path += '/'
|
||||
print(archive_path)
|
||||
|
||||
filename = os.path.join(archive_path, str(toot["id"]) + ".json")
|
||||
|
||||
# write toot to archive
|
||||
with open(filename, "w") as f:
|
||||
f.write(json.dumps(toot, indent=4, default=jsondefault))
|
||||
f.close()
|
||||
if not options.archive_deleted:
|
||||
# write toot to archive
|
||||
with open(filename, "w") as f:
|
||||
f.write(json.dumps(toot, indent=4, default=jsondefault))
|
||||
f.close()
|
||||
|
||||
toot_tags = set()
|
||||
for tag in toot.tags:
|
||||
@ -210,6 +211,12 @@ def checkToots(config, options, retry_count=0):
|
||||
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
|
||||
with open(filename, "w") as f:
|
||||
f.write(json.dumps(toot, indent=4, default=jsondefault))
|
||||
f.close()
|
||||
mastodon.status_unreblog(toot.reblog)
|
||||
else:
|
||||
if options.datestamp:
|
||||
@ -249,6 +256,12 @@ def checkToots(config, options, retry_count=0):
|
||||
+ str(format(diff / 60, ".0f"))
|
||||
+ " minutes.\n"
|
||||
)
|
||||
# check for --archive-deleted
|
||||
if options.archive_deleted and "id" in toot and "archive" in config:
|
||||
# write toot to archive
|
||||
with open(filename, "w") as f:
|
||||
f.write(json.dumps(toot, indent=4, default=jsondefault))
|
||||
f.close()
|
||||
|
||||
mastodon.status_delete(toot)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user