From 8fa9189518f5e8536456737f2624a5e2ce2ad7d1 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 13 Sep 2024 13:09:20 +0100 Subject: [PATCH] Function for if an actor is indexable by a search engine --- mastoapiv1.py | 6 ++---- mastoapiv2.py | 6 ++---- person.py | 5 ++--- utils.py | 16 ++++++++++++++++ 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/mastoapiv1.py b/mastoapiv1.py index 42f0d92b1..6a321f9d2 100644 --- a/mastoapiv1.py +++ b/mastoapiv1.py @@ -19,6 +19,7 @@ from utils import no_of_accounts from utils import get_status_count from utils import lines_in_file from utils import data_dir +from utils import account_is_indexable def _meta_data_instance_v1(show_accounts: bool, @@ -220,10 +221,7 @@ def _get_masto_api_v1account(base_dir: str, nickname: str, domain: str, joined_date = "2016-10-05T10:30:00Z" if account_json.get('published'): joined_date = account_json['published'] - noindex = True - if 'indexable' in account_json: - if account_json['indexable'] is True: - noindex = False + noindex = not account_is_indexable(account_json) discoverable = True if 'discoverable' in account_json: if account_json['discoverable'] is False: diff --git a/mastoapiv2.py b/mastoapiv2.py index ea136a6fc..25196e523 100644 --- a/mastoapiv2.py +++ b/mastoapiv2.py @@ -21,6 +21,7 @@ from utils import get_audio_extensions from utils import get_image_mime_type from utils import lines_in_file from utils import data_dir +from utils import account_is_indexable def _get_masto_api_v2id_from_nickname(nickname: str) -> int: @@ -96,10 +97,7 @@ def _meta_data_instance_v2(show_accounts: bool, image_url = remove_html(url_str) thumbnail_url = http_prefix + '://' + domain_full + '/login.png' admin_email = None - noindex = True - if 'indexable' in admin_actor: - if admin_actor['indexable'] is True: - noindex = False + noindex = not account_is_indexable(admin_actor) discoverable = True if 'discoverable' in admin_actor: if admin_actor['discoverable'] is False: diff --git a/person.py b/person.py index 65d82684f..a2af46a6c 100644 --- a/person.py +++ b/person.py @@ -37,6 +37,7 @@ from roles import set_role from roles import actor_roles_from_list from roles import get_actor_roles_list from media import process_meta_data +from utils import account_is_indexable from utils import get_image_mime_type from utils import get_instance_url from utils import get_url_from_post @@ -218,9 +219,7 @@ def get_actor_update_json(actor_json: {}) -> {}: memorial = False if actor_json.get('memorial'): memorial = True - indexable = False - if actor_json.get('indexable'): - indexable = True + indexable = account_is_indexable(actor_json) searchable_by = [] if actor_json.get('searchableBy'): if isinstance(actor_json['searchableBy'], list): diff --git a/utils.py b/utils.py index c6991e6e4..35dd900bf 100644 --- a/utils.py +++ b/utils.py @@ -5683,3 +5683,19 @@ def replace_strings(text: str, replacements: {}) -> str: for orig_str, new_str in replacements.items(): text = text.replace(orig_str, new_str) return text + + +def account_is_indexable(actor_json: {}) -> bool: + """Returns true if the given actor is indexable + """ + if 'indexable' not in actor_json: + return False + if isinstance(actor_json['indexable'], bool): + return actor_json['indexable'] + if isinstance(actor_json['indexable'], list): + if '#Public' in str(actor_json['indexable']): + return True + elif isinstance(actor_json['indexable'], str): + if '#Public' in actor_json['indexable']: + return True + return False