diff --git a/src/app.py b/src/app.py index 6d94e14..7ab03e8 100644 --- a/src/app.py +++ b/src/app.py @@ -5,6 +5,7 @@ from anilistapi.schemas.manga import Manga from komconfig import KomConfig from komcache import KomCache from komgapi import komgapi as KOMGAPI +from typing import Any, Dict, List app = Quart(__name__) @@ -12,6 +13,9 @@ cache = KomCache() cache.create_table( "CREATE TABLE IF NOT EXISTS manga_requests (id INTEGER PRIMARY KEY, manga_id INTEGER, grabbed BOOLEAN DEFAULT 0)" ) +cache.create_table( + "CREATE TABLE IF NOT EXISTS manga_titles (id INTEGER PRIMARY KEY, anilist_id INTEGER DEFAULT 0, komga_title UNIQUE)" +) settings = KomConfig() @@ -20,13 +24,31 @@ komga = KOMGAPI( username=settings.komga.user, password=settings.komga.password, ) -komga_books = komga.bookList() +komga_series = komga.seriesList() +# store the entries in the database table manga_titles, komga_series is a list of strings of the series names +for series in komga_series: + # check if the series is already in the database + existing_series = cache.fetch_one( + query="SELECT komga_title FROM manga_titles WHERE komga_title = ?", + args=(series,), + ) + if existing_series: + # series already exists, skip + continue + else: + cache.insert( + # insert into if not in database + query="INSERT OR IGNORE INTO manga_titles (komga_title) VALUES (?)", + args=(series,), + ) +komga_series = [series.lower() for series in komga_series] -async def fetch_data(data): +# Update type annotations for fetch_data +async def fetch_data(data: Dict[str, Any]) -> List[Dict[str, Any]]: async with httpx.AsyncClient() as client: try: - variables = {"search": data["query"]} + variables: Dict[str, Any] = {"search": data["query"]} if len(data["genres"]) > 0: variables["genres"] = data["genres"] if len(data["tags"]) > 0: @@ -42,10 +64,13 @@ async def fetch_data(data): response.raise_for_status() data = response.json() - results = [] + results: List[Dict[str, Any]] = [] for item in data.get("data", {}).get("Page", {}).get("media", []): manga = Manga(**item) - + in_komga = komga.getSeries( + manga.title.english if manga.title.english else manga.title.romaji + ) + print(in_komga, manga.title.english) results.append( { "id": manga.id, @@ -63,6 +88,7 @@ async def fetch_data(data): if manga.description else "No description available", "isAdult": manga.isAdult, + "in_komga": in_komga, } ) @@ -122,13 +148,13 @@ async def search(): @app.route("/", methods=["GET"]) async def index(): - return await render_template("index.html") + return await render_template("index.html", komga_series=komga_series) @app.route("/request", methods=["POST"]) async def log_request(): data = await request.get_json() - item = data.get("item") + item = data.get("title") if item: asynccache = KomCache() manga_title = data.get("title") diff --git a/src/static/style.css b/src/static/style.css index 3422a10..e5f0eb2 100644 --- a/src/static/style.css +++ b/src/static/style.css @@ -153,4 +153,13 @@ body.nsfw-disabled .image-container.nsfw:hover img { .request { /* Implement design here */ +} + +.card.komga { + border: 3px solid green; + box-sizing: border-box; + /* disable the request button for entries in Komga */ + pointer-events: none; + opacity: 0.5; + } \ No newline at end of file diff --git a/src/templates/index.html b/src/templates/index.html index a544b30..b5ad9cc 100644 --- a/src/templates/index.html +++ b/src/templates/index.html @@ -14,17 +14,17 @@
{{ result.title }}