summaryrefslogtreecommitdiff
path: root/web.py
diff options
context:
space:
mode:
authorKeuin <[email protected]>2023-06-01 01:02:22 +0800
committerKeuin <[email protected]>2023-06-01 01:02:22 +0800
commit093c815e9e3ee8aecf92cb1de7b51337ca28c16e (patch)
tree986f76278f389591cd2fafc81b963e84d57e6c1d /web.py
parentc71f0eeb1be07c4085b2eb6f0e03388c4bce695e (diff)
implement tex resource API
Diffstat (limited to 'web.py')
-rw-r--r--web.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/web.py b/web.py
index 63d315d..7aadac4 100644
--- a/web.py
+++ b/web.py
@@ -1,6 +1,9 @@
import re
-from fastapi import FastAPI
+import aiohttp
+from fastapi import FastAPI, Response
+
+import main
app = FastAPI()
@@ -8,5 +11,17 @@ utaten_pattern = re.compile(r'[a-z0-9]+')
@app.get("/utaten/{item_id}/pdf")
-def get_utaten_lyric_pdf(item_id: str):
+async def get_utaten_lyric_pdf(item_id: str):
raise NotImplementedError
+
+
[email protected]("/utaten/{item_id}.tex")
+async def get_utaten_lyric_pdf(item_id: str, resp: Response):
+ async with aiohttp.ClientSession() as ses:
+ async with ses.get(f'https://utaten.com/lyric/{item_id}/') as r:
+ if not r.ok:
+ resp.status_code = 503
+ return
+ html = await r.text()
+ tex = main.html_to_tex(html)
+ return Response(content=tex, media_type='application/x-tex')