From 2bea936cf2906d569e5e68ffec0148383101c97f Mon Sep 17 00:00:00 2001 From: io Date: Tue, 21 Sep 2021 13:58:20 +0000 Subject: [PATCH] fix fetching from masto instances --- fetch_posts.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/fetch_posts.py b/fetch_posts.py index ededd86..bb40544 100755 --- a/fetch_posts.py +++ b/fetch_posts.py @@ -9,6 +9,7 @@ import pendulum import operator import aiosqlite import contextlib +from yarl import URL from pleroma import Pleroma from bs4 import BeautifulSoup from functools import partial @@ -81,8 +82,16 @@ class PostFetcher: await self._fedi.verify_credentials() self._completed_accounts = {} async with anyio.create_task_group() as tg: - for acc in map(operator.itemgetter('fqn'), await self._fedi.following()): - tg.start_soon(self._do_account, acc) + for fqn in map(self.fqn, await self._fedi.following()): + tg.start_soon(self._do_account, fqn) + + def fqn(self, acc: dict): + try: + return acc['fqn'] + except KeyError: + fqn = acc['acct'] + if '@' in fqn: return fqn + return fqn + '@' + URL(self.config['site']).host async def _do_account(self, acc: AccountHandle): async with anyio.create_task_group() as tg: