From 5ed751a8c633c7af8ec38759f4f8b6a7cc441ab1 Mon Sep 17 00:00:00 2001 From: Andrew Kvalheim Date: Mon, 1 Jul 2024 18:01:03 -0700 Subject: [PATCH] Skip fetching context of private posts Context fetching is performed without authentication, so it is only possible for public and unlisted posts. --- find_posts.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/find_posts.py b/find_posts.py index 2ccf8699..95d4559b 100644 --- a/find_posts.py +++ b/find_posts.py @@ -479,6 +479,14 @@ def get_reply_toots(user_id, server, access_token, seen_urls, reply_since): f"Error getting replies for user {user_id} on server {server}. Status code: {resp.status_code}" ) + +def toot_context_can_be_fetched(toot): + fetchable = toot["visibility"] in ["public", "unlisted"] + if not fetchable: + logger.debug(f"Cannot fetch context of private toot {toot['uri']}") + return fetchable + + def toot_context_should_be_fetched(toot): if toot['uri'] not in recently_checked_context: recently_checked_context[toot['uri']] = toot @@ -512,7 +520,7 @@ def get_all_known_context_urls(server, reply_toots, parsed_urls, seen_hosts): if toot_has_parseable_url(toot, parsed_urls): url = toot["url"] if toot["reblog"] is None else toot["reblog"]["url"] parsed_url = parse_url(url, parsed_urls) - if(toot_context_should_be_fetched(toot)): + if toot_context_can_be_fetched(toot) and toot_context_should_be_fetched(toot): recently_checked_context[toot['uri']]['lastSeen'] = datetime.now(datetime.now().astimezone().tzinfo) context = get_toot_context(parsed_url[0], parsed_url[1], url, seen_hosts) if context is not None: