From 0f10bfddac893421f16ac0ca038fbba2a8cac8cd Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Mon, 5 Dec 2022 22:01:37 +0100 Subject: [PATCH] Oops add missing file --- app/utils/mastodon.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 app/utils/mastodon.py diff --git a/app/utils/mastodon.py b/app/utils/mastodon.py new file mode 100644 index 0000000..4afc7de --- /dev/null +++ b/app/utils/mastodon.py @@ -0,0 +1,32 @@ +from pathlib import Path + +from loguru import logger + +from app.webfinger import get_actor_url + + +def _load_mastodon_following_accounts_csv_file(path: str) -> list[str]: + handles = [] + for line in Path(path).read_text().splitlines()[1:]: + handle = line.split(",")[0] + handles.append(handle) + + return handles + + +async def get_actor_urls_from_following_accounts_csv_file( + path: str, +) -> list[tuple[str, str]]: + actor_urls = [] + for handle in _load_mastodon_following_accounts_csv_file(path): + try: + actor_url = await get_actor_url(handle) + except Exception: + logger.error("Failed to fetch actor URL for {handle=}") + else: + if actor_url: + actor_urls.append((handle, actor_url)) + else: + logger.info(f"No actor URL found for {handle=}") + + return actor_urls