feat: add a check to see if an entry is already in komga, if so, reduce opacity, add border, disable buttons closes #6
This commit is contained in:
40
src/app.py
40
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")
|
||||
|
||||
Reference in New Issue
Block a user