From 39942133259bfe6ea3f6a916681b2973d444e0de Mon Sep 17 00:00:00 2001 From: SouthFox Date: Mon, 26 Feb 2024 23:55:18 +0800 Subject: [PATCH] [refactor] use hylang to fetch --- app/actor.py | 6 ++++-- app/hyap.hy | 13 +++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 app/hyap.hy diff --git a/app/actor.py b/app/actor.py index b093f4c..b17b767 100644 --- a/app/actor.py +++ b/app/actor.py @@ -1,11 +1,13 @@ #!/usr/bin/env python3 """Actor stuff.""" import typing +import hy + from urllib.parse import urlparse from sqlalchemy import select from loguru import logger -import app.activitypub as ap +from app.hyap import fetch # type: ignore from app import models from app.database import AsyncSession @@ -31,7 +33,7 @@ async def fetch_actor( if exist_actor: return exist_actor - ap_object = await ap.fetch(actor_id) + ap_object = await fetch(actor_id) exist_actor = await save_actor(ap_object, db_session) return exist_actor diff --git a/app/hyap.hy b/app/hyap.hy new file mode 100644 index 0000000..9ba82e3 --- /dev/null +++ b/app/hyap.hy @@ -0,0 +1,13 @@ +#!/usr/bin/env hy +(import httpx) +(import loguru [logger]) +(import app [config]) + +(defn/a fetch + [url] + (.info logger url) + (return (.json + (with/a [client (.AsyncClient httpx)] + (await (.get client url :headers + {"User-Agent" config.USER_AGENT + "Accept" config.AP_CONTENT_TYPE}))))))