Merge pull request #29 from jpmens/archive
Add support for archiving toots into JSON files
This commit is contained in:
commit
81afe39581
|
@ -87,6 +87,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 | The full toot is archived into individual files named by the Toot's `id` in this writeable 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:
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
# toots_to_keep : a list of toot ids indicating toots to be kept regardless of other settings
|
||||
# hashtags_to_keep : a list of hashtags, where any toots with any of these hashtags will be kept. Do not include the '#' symbol
|
||||
# visibility_to_keep : any toots with visibility settings in this list will be kept. Options are: 'public', 'unlisted', 'private', 'direct'
|
||||
# archive : path to a writeable directory into which toots are "archived" as JSON files
|
||||
|
||||
# you can list only one user, or multiple users
|
||||
# each user account should be preceded by a single dash, and indented, as per below
|
||||
|
|
|
@ -79,8 +79,17 @@ def checkToots(config, options, retry_count=0):
|
|||
+ config['base_url']
|
||||
)
|
||||
|
||||
def jsondefault(obj):
|
||||
if isinstance(obj, (date, datetime)):
|
||||
return obj.isoformat()
|
||||
def checkBatch(timeline, deleted_count=0):
|
||||
for toot in timeline:
|
||||
if 'id' in toot and 'archive' in config:
|
||||
print(toot)
|
||||
filename = os.path.join(config['archive'], str(toot['id']) + '.json')
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue