From b7ef2be02e8633d08267705f354234d5755c046f Mon Sep 17 00:00:00 2001 From: Timothy Quilling Date: Thu, 29 Jun 2023 01:57:33 -0400 Subject: [PATCH] chore: refactor get_all_known_context_urls --- find_posts.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/find_posts.py b/find_posts.py index 2ad366b..8d5fb3c 100644 --- a/find_posts.py +++ b/find_posts.py @@ -356,21 +356,20 @@ def get_reply_toots(user_id, server, access_token, seen_urls, reply_since): ) -def get_all_known_context_urls(server, reply_toots,parsed_urls): +def get_all_known_context_urls(server, reply_toots, parsed_urls): """get the context toots of the given toots from their original server""" - known_context_urls = set( - filter( - lambda url: not url.startswith(f"https://{server}/"), - itertools.chain.from_iterable( - get_toot_context(*parse_url(toot["url"] if toot["reblog"] is None else toot["reblog"]["url"],parsed_urls), toot["url"]) - for toot in filter( - lambda toot: toot_has_parseable_url(toot,parsed_urls), - reply_toots - ) - ), - ) - ) + known_context_urls = set() + + for toot in reply_toots: + 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) + context = get_toot_context(parsed_url[0], parsed_url[1], url) + known_context_urls.update(context) # type: ignore + + known_context_urls = set(filter(lambda url: not url.startswith(f"https://{server}/"), known_context_urls)) log(f"Found {len(known_context_urls)} known context toots") + return known_context_urls @@ -1050,4 +1049,4 @@ if __name__ == "__main__": get(f"{arguments.on_fail}?rid={runId}") except Exception as ex: log(f"Error getting callback url: {ex}") - raise + raise \ No newline at end of file