Add last status date to masto API

main
Bob Mottram 2023-10-02 15:09:06 +01:00
parent bfd9e96760
commit 4602c7f7bc
2 changed files with 29 additions and 0 deletions

View File

@ -101,6 +101,7 @@ def _get_masto_api_v1account(base_dir: str, nickname: str, domain: str,
no_of_followers = 0
no_of_following = 0
fields = []
published = None
if show_accounts and not broch_mode:
no_of_followers = _lines_in_file(account_dir + '/followers.txt')
no_of_following = _lines_in_file(account_dir + '/following.txt')
@ -131,6 +132,16 @@ def _get_masto_api_v1account(base_dir: str, nickname: str, domain: str,
"value": tag[prop_value_name],
"verified_at": None
})
published_filename = \
acct_dir(base_dir, nickname, domain) + '/.last_published'
if os.path.isfile(published_filename):
try:
with open(published_filename, 'r',
encoding='utf-8') as fp_pub:
published = fp_pub.read()
except OSError:
print('EX: unable to read last published time ' +
published_filename)
masto_account_json = {
"id": get_masto_api_v1id_from_nickname(nickname),
@ -156,6 +167,8 @@ def _get_masto_api_v1account(base_dir: str, nickname: str, domain: str,
"roles": [],
"fields": fields
}
if published:
masto_account_json['last_status_at'] = published
return masto_account_json

View File

@ -954,9 +954,14 @@ def save_post_to_box(base_dir: str, http_prefix: str, post_id: str,
local_actor_url(http_prefix, nickname, original_domain) + \
'/statuses/' + status_number
post_json_object['id'] = post_id + '/activity'
published = None
if post_json_object.get('published'):
published = post_json_object['published']
if has_object_dict(post_json_object):
post_json_object['object']['id'] = post_id
post_json_object['object']['atomUri'] = post_id
if post_json_object['object'].get('published'):
published = post_json_object['object']['published']
box_dir = create_person_dir(nickname, domain, base_dir, boxname)
filename = box_dir + '/' + post_id.replace('/', '#') + '.json'
@ -965,6 +970,17 @@ def save_post_to_box(base_dir: str, http_prefix: str, post_id: str,
# if this is an outbox post with a duplicate in the inbox then save to both
# This happens for edited posts
if '/outbox/' in filename:
if published:
published_filename = \
acct_dir(base_dir, nickname, domain) + '/.last_published'
try:
with open(published_filename, 'w+',
encoding='utf-8') as fp_last:
fp_last.write(published)
except OSError:
print('EX: unable to save last published time ' +
published_filename)
inbox_filename = filename.replace('/outbox/', '/inbox/')
if os.path.isfile(inbox_filename):
save_json(post_json_object, inbox_filename)