From 4602c7f7bc7b492fbd860dba906f128259b63f34 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 2 Oct 2023 15:09:06 +0100 Subject: [PATCH] Add last status date to masto API --- mastoapiv1.py | 13 +++++++++++++ posts.py | 16 ++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/mastoapiv1.py b/mastoapiv1.py index 9eeea17cb..3ab8134a5 100644 --- a/mastoapiv1.py +++ b/mastoapiv1.py @@ -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 diff --git a/posts.py b/posts.py index d40bf558c..8b73bbb4b 100644 --- a/posts.py +++ b/posts.py @@ -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)