#!/usr/bin/env python3
"""hc41: ambil isi 3 artikel (judul + konten teks) via WP REST."""
import json, re, subprocess, html

SLUGS = [
    "data-analytics-rumah-sakit-kebutuhan-pasien",
    "panduan-seo-klinik-rumah-sakit",
    "klinik-kecil-butuh-digital-marketing",
]

out = {}
for s in SLUGS:
    r = subprocess.run(["curl", "-s", "--http1.1", "--max-time", "120", "-A", "Mozilla/5.0",
                        "https://studiosoft.id/wp-json/wp/v2/posts?slug=%s&_fields=id,date,slug,title,link,content" % s],
                       capture_output=True, text=True)
    try:
        d = json.loads(r.stdout)
    except Exception as e:
        print("GAGAL", s, r.stdout[:200]); continue
    if not d:
        print("KOSONG", s); continue
    p = d[0]
    txt = re.sub(r"<[^>]+>", "\n", p["content"]["rendered"])
    txt = html.unescape(txt)
    lines = [l.strip() for l in txt.split("\n")]
    lines = [l for l in lines if l and len(l) > 25]
    out[s] = {"title": html.unescape(re.sub(r"<[^>]+>", "", p["title"]["rendered"])),
              "link": p["link"], "date": p["date"], "paras": lines}
    print("=" * 90)
    print(out[s]["title"], "|", p["date"][:10], "|", p["link"])
    for l in lines:
        print("  -", l)

json.dump(out, open("/tmp/hc41_articles.json", "w"), indent=1)
