This commit is contained in:
parent
5937e71dc3
commit
3994213325
2 changed files with 17 additions and 2 deletions
|
@ -1,11 +1,13 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
"""Actor stuff."""
|
"""Actor stuff."""
|
||||||
import typing
|
import typing
|
||||||
|
import hy
|
||||||
|
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
import app.activitypub as ap
|
from app.hyap import fetch # type: ignore
|
||||||
from app import models
|
from app import models
|
||||||
from app.database import AsyncSession
|
from app.database import AsyncSession
|
||||||
|
|
||||||
|
@ -31,7 +33,7 @@ async def fetch_actor(
|
||||||
if exist_actor:
|
if exist_actor:
|
||||||
return 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)
|
exist_actor = await save_actor(ap_object, db_session)
|
||||||
return exist_actor
|
return exist_actor
|
||||||
|
|
||||||
|
|
13
app/hyap.hy
Normal file
13
app/hyap.hy
Normal file
|
@ -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}))))))
|
Loading…
Reference in a new issue