kopia lustrzana https://git.sr.ht/~tsileo/microblog.pub
Porównaj commity
3 Commity
5d95fd44ac
...
0f10bfddac
Autor | SHA1 | Data |
---|---|---|
Thomas Sileo | 0f10bfddac | |
Thomas Sileo | 26efd09304 | |
Thomas Sileo | f2e531cf1a |
2
Makefile
2
Makefile
|
@ -28,7 +28,7 @@ move-to:
|
|||
|
||||
.PHONY: self-destruct
|
||||
self-destruct:
|
||||
-docker run --rm --volume `pwd`/data:/app/data --volume `pwd`/app/static:/app/app/static microblogpub/microblogpub inv self-destruct
|
||||
-docker run --rm --it --volume `pwd`/data:/app/data --volume `pwd`/app/static:/app/app/static microblogpub/microblogpub inv self-destruct
|
||||
|
||||
.PHONY: reset-password
|
||||
reset-password:
|
||||
|
|
|
@ -950,7 +950,7 @@ async def compute_all_known_recipients(db_session: AsyncSession) -> set[str]:
|
|||
}
|
||||
|
||||
|
||||
async def _get_following(db_session: AsyncSession) -> list[models.Follower]:
|
||||
async def _get_following(db_session: AsyncSession) -> list[models.Following]:
|
||||
return (
|
||||
(
|
||||
await db_session.scalars(
|
||||
|
|
|
@ -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
|
37
tasks.py
37
tasks.py
|
@ -353,3 +353,40 @@ def check_config(ctx):
|
|||
sys.exit(1)
|
||||
else:
|
||||
print("Config is OK")
|
||||
|
||||
|
||||
@task
|
||||
def import_mastodon_following_accounts(ctx, path):
|
||||
# type: (Context, str) -> None
|
||||
from loguru import logger
|
||||
|
||||
from app.boxes import _get_following
|
||||
from app.boxes import _send_follow
|
||||
from app.database import async_session
|
||||
from app.utils.mastodon import get_actor_urls_from_following_accounts_csv_file
|
||||
|
||||
async def _import_following() -> int:
|
||||
count = 0
|
||||
async with async_session() as db_session:
|
||||
followings = {
|
||||
following.ap_actor_id for following in await _get_following(db_session)
|
||||
}
|
||||
for (
|
||||
handle,
|
||||
actor_url,
|
||||
) in await get_actor_urls_from_following_accounts_csv_file(path):
|
||||
if actor_url in followings:
|
||||
logger.info(f"Already following {handle}")
|
||||
continue
|
||||
|
||||
logger.info(f"Importing {actor_url=}")
|
||||
|
||||
await _send_follow(db_session, actor_url)
|
||||
count += 1
|
||||
|
||||
await db_session.commit()
|
||||
|
||||
return count
|
||||
|
||||
count = asyncio.run(_import_following())
|
||||
logger.info(f"Import done, {count} follow requests sent")
|
||||
|
|
Ładowanie…
Reference in New Issue