"""Ručni test: Wikipedia -> (opciono) sažetak -> PDF. Bez ključa radi sa sirovim tekstom članka i slikom sa Wikipedije.""" import asyncio import html import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) from idriz import render, textgen, wiki # noqa: E402 from idriz.config import load # noqa: E402 async def main(topic: str, age: str) -> None: cfg = load() art = wiki.find_article(topic) if not art: print("nema članka"); return print("članak:", art.title, art.url, len(art.text), "znakova") out = Path("out"); out.mkdir(exist_ok=True) url = wiki.page_image_url(art.title) image = None if url: raw = out / ("test-wiki" + Path(url).suffix.lower()) if wiki.download(url, raw): image = render.prepare_image(raw, out / "test-img.png") print("slika:", url, "->", image) if cfg.openai_api_key: from openai import AsyncOpenAI s = await textgen.summarize(AsyncOpenAI(api_key=cfg.openai_api_key), cfg.text_model, art, topic, age) title, body, facts, caption = s.title, s.html, s.facts, s.caption else: paras = [p for p in art.text.split("\n\n") if p and not p.startswith("==")][:5] title, body = art.title, "".join(f"
{html.escape(p[:600])}
" for p in paras) facts = ["Ovo je probna zanimljivost broj jedan.", "Druga zanimljivost, kratka.", "Treća, još kraća."] caption = "Probni potpis ispod slike." pdf = render.render_summary(title, body, facts, caption, image, art.title, out / "test-sazetak.pdf", cfg.max_pages) print("PDF:", pdf) if __name__ == "__main__": asyncio.run(main(sys.argv[1] if len(sys.argv) > 1 else "Volcano", sys.argv[2] if len(sys.argv) > 2 else "10"))