CI / test (push) Has been cancelled
Quivio (Kofferwort aus Quire + Video) ersetzt den Arbeitstitel WatchStack. Es ist origineller, frei auf PyPI/npm, und passt perfekt zur Doppelnatur der App: Buecher (Quire) + Serien (Video). Geaendert: - Python-Paket app/ -> quivio/ (+ alle Imports angepasst) - DB-File watchstack.db -> quivio.db - Docker-Image: quivio:0.5.1-beta, Container-Name quivio - Compose-Services: quivio, quivio-local - ENV-Vars: QUIVIO_VERSION, QUIVIO_PORT, Volume quivio-data - Frontend-Logo "W" -> "Q", Titel "Quivio", Footer - Favicon "Q" (Georgia serif fuer klassischen Look) - Logger-Name: watchstack -> quivio - README, NOTICE, dist/README, data/README: Quivio - CI-Workflow: testet quivio/ Pfade - build-and-push.sh: lokaler Tag "quivio:VERSION" - service-Feld in /api/health: quivio - OpenAPI title: Quivio Bugfix (gefunden beim Renaming): - seed.py hatte versteckten "from app.database import DB_PATH" — gefixt Verifiziert end-to-end: - Python-Import OK - Backend: service=quivio, version=0.5.1-beta, 8 unique items - Docker-Build OK, Push in Gitea-Registry OK (neuer sha256-Digest) - Container: Quivio 0.5.1-beta ready (logger), HTML ohne WatchStack-Rest - OpenAPI title=Quivio - 8 unique items nach cold start (Race-Fix haelt)
74 lines
2.4 KiB
Python
74 lines
2.4 KiB
Python
"""Externe Cover-/Metadaten-Quellen (Open Library)."""
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
import os
|
|
from typing import Optional
|
|
|
|
import httpx
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
OL_SEARCH = "https://openlibrary.org/search.json"
|
|
OL_COVER = "https://covers.openlibrary.org/b/isbn/{isbn}-L.jpg"
|
|
DEFAULT_TIMEOUT = float(os.environ.get("WATCHSTACK_HTTP_TIMEOUT", "8"))
|
|
|
|
|
|
def lookup_book_by_isbn(isbn: str, *, timeout: float = DEFAULT_TIMEOUT) -> Optional[dict]:
|
|
"""Sucht Buchdaten anhand ISBN via Open Library."""
|
|
if not isbn:
|
|
return None
|
|
isbn = isbn.strip().replace("-", "").replace(" ", "")
|
|
try:
|
|
with httpx.Client(timeout=timeout) as client:
|
|
r = client.get(OL_SEARCH, params={"isbn": isbn, "limit": 1})
|
|
r.raise_for_status()
|
|
data = r.json()
|
|
except Exception as exc: # pragma: no cover
|
|
log.warning("Open-Library-Suche fehlgeschlagen: %s", exc)
|
|
return None
|
|
|
|
docs = data.get("docs") or []
|
|
if not docs:
|
|
return None
|
|
d = docs[0]
|
|
return {
|
|
"title": d.get("title"),
|
|
"original_title": d.get("title"),
|
|
"author": ", ".join(d.get("author_name") or []) or None,
|
|
"release_year": d.get("first_publish_year"),
|
|
"cover_url": OL_COVER.format(isbn=isbn) if isbn else None,
|
|
"total_pages": d.get("number_of_pages_median"),
|
|
"description": None, # OL liefert hier keine handliche Kurzbeschreibung
|
|
}
|
|
|
|
|
|
def lookup_book_by_title(title: str, *, timeout: float = DEFAULT_TIMEOUT) -> Optional[dict]:
|
|
"""Sucht Buchdaten anhand Titel (Fallback)."""
|
|
if not title:
|
|
return None
|
|
try:
|
|
with httpx.Client(timeout=timeout) as client:
|
|
r = client.get(OL_SEARCH, params={"title": title, "limit": 1})
|
|
r.raise_for_status()
|
|
data = r.json()
|
|
except Exception as exc: # pragma: no cover
|
|
log.warning("Open-Library-Suche fehlgeschlagen: %s", exc)
|
|
return None
|
|
docs = data.get("docs") or []
|
|
if not docs:
|
|
return None
|
|
d = docs[0]
|
|
isbn = None
|
|
isbns = d.get("isbn") or []
|
|
if isbns:
|
|
isbn = isbns[0]
|
|
return {
|
|
"title": d.get("title"),
|
|
"author": ", ".join(d.get("author_name") or []) or None,
|
|
"release_year": d.get("first_publish_year"),
|
|
"cover_url": OL_COVER.format(isbn=isbn) if isbn else None,
|
|
"total_pages": d.get("number_of_pages_median"),
|
|
}
|