Fix non-absolute archive filepaths breaking

Archive paths can now be relative (not recommended) or use tildes

Also improves documentation of archive function both in README and example config.
This commit is contained in:
Hugh Rundle 2020-07-18 15:45:20 +10:00
parent 594f5dd5c6
commit 9803e16f95
3 changed files with 21 additions and 7 deletions

View File

@ -90,7 +90,7 @@ You can now enter the configuration details for each user:
| toots_to_keep | A list of toot ids indicating toots to be kept regardless of other settings. The ID of a toot is the last part of its individual URL. e.g. for [https://ausglam.space/@hugh/101294246770105799](https://ausglam.space/@hugh/101294246770105799) the id is `101294246770105799` |
| hashtags_to_keep | A list of hashtags, where any toots with any of these hashtags will be kept regardless of age. Do not include the '#' symbol. Do remember the [rules for hashtags](https://docs.joinmastodon.org/user/posting/#hashtags) |
| visibility_to_keep | Toots with any of the visibility settings in this list will be kept regardless of age. Options are: `public`, `unlisted`, `private`, `direct`. |
| archive | A string. The full toot is archived into individual files named by the toot's `id` in this writeable directory. |
| archive | A string representing the filepath to your toot archive. The full toot is archived into individual files named by the toot's `id` in this writeable directory. It is generally best to use an absolute file path - relative paths will not work if you call `ephemetoot` from another directory. |
All values other than `access_token`, `username` and `base_url` are optional, however if you include `toots_to_keep`, `hashtags_to_keep`, or `visibility_to_keep` you must make each a list, even if it is empty:
@ -105,6 +105,8 @@ If you want to use `ephemetoot` for multiple accounts, separate the config for e
# Running the script
For a short description of all available options, run `ephemetoot --help` from the command line.
It is **strongly recommended** that you do a test run before using `ephemetoot` live. There is no "undo"!
## Running in test mode

View File

@ -11,7 +11,7 @@
# you can list only one user, or multiple users
# each user account should be preceded by a single dash, and indented, as per below
-
# ausglam.space account
# full example
access_token : ZA-Yj3aBD8U8Cm7lKUp-lm9O9BmDgdhHzDeqsY8tlL0
username : alice
base_url : ausglam.space
@ -27,9 +27,9 @@
visibility_to_keep :
- direct
- private
archive : ~/toots_archive/
archive : Users/alice/toots_archive/ausglam/
-
# aus.social account
# minimal example
# values other than access_token, username, and base_url are all optional
access_token : AZ-Yj3aBD8U8Cm7lKUp-lm9O9BmDgdhHzDeqsY8tlL9
username : bob

View File

@ -106,12 +106,24 @@ def checkToots(config, options, retry_count=0):
def checkBatch(timeline, deleted_count=0):
for toot in timeline:
if "id" in toot and "archive" in config:
filename = os.path.join(
config["archive"], str(toot["id"]) + ".json"
)
# define archive path
if config["archive"][0] == '~':
archive_path = os.path.expanduser(config["archive"])
elif config["archive"][0] == '/':
archive_path = config["archive"]
else:
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()
toot_tags = set()
for tag in toot.tags:
toot_tags.add(tag.name)