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
|
vnum = pkg_resources.require("ephemetoot")[0].version
|
||||||
|
|
||||||
parser = ArgumentParser()
|
parser = ArgumentParser()
|
||||||
|
parser.add_argument(
|
||||||
|
"--archive-deleted", action="store_true", help="Only archive toots that are being deleted"
|
||||||
|
)
|
||||||
parser.add_argument(
|
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'."
|
"--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)"
|
"--datestamp", action="store_true", help="Include a datetime stamp for every action (e.g. deleting a toot)"
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
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(
|
parser.add_argument(
|
||||||
"--pace", action="store_true", help="Slow deletion actions to match API rate limit to avoid pausing"
|
"--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('================================================')
|
||||||
print('')
|
print('')
|
||||||
if options.test:
|
if options.test:
|
||||||
print("This is a test run...")
|
print("This is a test run...\n")
|
||||||
print('')
|
|
||||||
with open(config_file) as config:
|
with open(config_file) as config:
|
||||||
for accounts in yaml.safe_load_all(config):
|
for accounts in yaml.safe_load_all(config):
|
||||||
for user in accounts:
|
for user in accounts:
|
||||||
|
@ -116,13 +116,14 @@ def checkToots(config, options, retry_count=0):
|
|||||||
archive_path = os.path.join( os.getcwd(), config["archive"] )
|
archive_path = os.path.join( os.getcwd(), config["archive"] )
|
||||||
if archive_path[-1] != '/':
|
if archive_path[-1] != '/':
|
||||||
archive_path += '/'
|
archive_path += '/'
|
||||||
print(archive_path)
|
|
||||||
filename = os.path.join(archive_path, str(toot["id"]) + ".json")
|
filename = os.path.join(archive_path, str(toot["id"]) + ".json")
|
||||||
|
|
||||||
# write toot to archive
|
if not options.archive_deleted:
|
||||||
with open(filename, "w") as f:
|
# write toot to archive
|
||||||
f.write(json.dumps(toot, indent=4, default=jsondefault))
|
with open(filename, "w") as f:
|
||||||
f.close()
|
f.write(json.dumps(toot, indent=4, default=jsondefault))
|
||||||
|
f.close()
|
||||||
|
|
||||||
toot_tags = set()
|
toot_tags = set()
|
||||||
for tag in toot.tags:
|
for tag in toot.tags:
|
||||||
@ -210,6 +211,12 @@ def checkToots(config, options, retry_count=0):
|
|||||||
print(
|
print(
|
||||||
"Rate limit reached. Waiting for a rate limit reset"
|
"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)
|
mastodon.status_unreblog(toot.reblog)
|
||||||
else:
|
else:
|
||||||
if options.datestamp:
|
if options.datestamp:
|
||||||
@ -249,7 +256,13 @@ def checkToots(config, options, retry_count=0):
|
|||||||
+ str(format(diff / 60, ".0f"))
|
+ str(format(diff / 60, ".0f"))
|
||||||
+ " minutes.\n"
|
+ " 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)
|
mastodon.status_delete(toot)
|
||||||
|
|
||||||
except MastodonRatelimitError:
|
except MastodonRatelimitError:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user