from app.database import SessionLocal
from app.models.article import Article
from app.services import autolink

db = SessionLocal()
rows = db.query(Article).filter(Article.deleted_at.is_(None)).all()
matchers = autolink.index([(a.title, a.slug) for a in rows if (a.status or "") == "published"])
for want in ("Nephrotic Syndrome", "Asthma", "Kawasaki Disease"):
    art = next((a for a in rows if a.title == want), None)
    if not art:
        continue
    sec = next((s for s in (art.sections or []) if (s.get("variant") or "long") == "long"), None)
    if not sec:
        continue
    out, n = autolink.apply(sec.get("content") or "", matchers, skip=art.slug)
    print(f"=== {want} / {sec.get('title')} — {n} links")
    print(out[:900])
    print()
db.close()
