Skip to content

Commit

Permalink
refactor: move to subfolder
Browse files Browse the repository at this point in the history
  • Loading branch information
pikdum committed May 4, 2024
1 parent 31cdfe5 commit 3a4aef2
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web: uvicorn mona:app
web: uvicorn mona.app:app
5 changes: 0 additions & 5 deletions anitopy.pyi

This file was deleted.

1 change: 1 addition & 0 deletions mona/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#!/usr/bin/env python3
10 changes: 6 additions & 4 deletions mona.py → mona/app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python3
import os
import random
import re
Expand All @@ -12,7 +13,7 @@
from loguru import logger
from lxml import html

from tvdb import TVDB
from .tvdb import TVDB

app = FastAPI(docs_url="/", redoc_url=None)

Expand Down Expand Up @@ -119,8 +120,7 @@ async def get_subsplease_poster(name: str) -> str | None:

@app.get("/poster")
async def poster(query: str):
parsed = anitopy.parse(query)
if not parsed or not (title := parsed.get("anime_title")):
if not (parsed := anitopy.parse(query)) or not (title := parsed.get("anime_title")):
raise HTTPException(status_code=400, detail="query is invalid")
poster = await get_tvdb_poster(parsed)
if poster:
Expand Down Expand Up @@ -158,7 +158,9 @@ async def get_fanart(parsed: dict[str, str]) -> list[dict] | None:

@app.get("/fanart")
async def fanart(query: str):
fanart = await get_fanart(anitopy.parse(query))
if not (parsed := anitopy.parse(query)) or not (title := parsed.get("anime_title")):
raise HTTPException(status_code=400, detail="query is invalid")
fanart = await get_fanart(title)
if not fanart or not (image := random.choice(fanart).get("image")):
return HTTPException(status_code=404, detail="fanart not found")
return RedirectResponse(url=image, status_code=302)
Expand Down
File renamed without changes.

0 comments on commit 3a4aef2

Please sign in to comment.