Add support for archiving toots into JSON files
This commit is contained in:
parent
a1db933bbd
commit
c0d680258f
|
@ -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` |
|
| 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) |
|
| 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`. |
|
| 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:
|
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
|
# 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
|
# 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'
|
# 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
|
# you can list only one user, or multiple users
|
||||||
# each user account should be preceded by a single dash, and indented, as per below
|
# each user account should be preceded by a single dash, and indented, as per below
|
||||||
|
@ -32,4 +33,4 @@
|
||||||
access_token : AZ-Yj3aBD8U8Cm7lKUp-lm9O9BmDgdhHzDeqsY8tlL9
|
access_token : AZ-Yj3aBD8U8Cm7lKUp-lm9O9BmDgdhHzDeqsY8tlL9
|
||||||
username : bob
|
username : bob
|
||||||
base_url : aus.social
|
base_url : aus.social
|
||||||
days_to_keep : 30
|
days_to_keep : 30
|
||||||
|
|
|
@ -79,8 +79,17 @@ def checkToots(config, options, retry_count=0):
|
||||||
+ config['base_url']
|
+ config['base_url']
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def jsondefault(obj):
|
||||||
|
if isinstance(obj, (date, datetime)):
|
||||||
|
return obj.isoformat()
|
||||||
def checkBatch(timeline, deleted_count=0):
|
def checkBatch(timeline, deleted_count=0):
|
||||||
for toot in timeline:
|
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()
|
toot_tags = set()
|
||||||
for tag in toot.tags:
|
for tag in toot.tags:
|
||||||
toot_tags.add(tag.name)
|
toot_tags.add(tag.name)
|
||||||
|
@ -317,4 +326,4 @@ def checkToots(config, options, retry_count=0):
|
||||||
print( 'Attempt ' + str(retry_count + 1) )
|
print( 'Attempt ' + str(retry_count + 1) )
|
||||||
checkToots(config, options, retry_count)
|
checkToots(config, options, retry_count)
|
||||||
else:
|
else:
|
||||||
print('Gave up waiting for network')
|
print('Gave up waiting for network')
|
||||||
|
|
Loading…
Reference in New Issue