#!/usr/bin/env python3
"""Baca balik post #10388 (TSC) untuk memastikan jadwal, isi, meta, dan gambar tersimpan."""
import sys

WS = "/home/mantapman/.hermes/profiles/atun/workspace"
sys.path.insert(0, WS)
from tsc_http import CFG, rest_json, xmlrpc_call  # noqa: E402

PID = 10388
st, d = rest_json("GET", f"/wp-json/wp/v2/posts/{PID}?context=edit&_fields=id,status,date,date_gmt,"
                         f"slug,link,featured_media,title,content,comment_status")
print("HTTP", st)
if isinstance(d, dict):
    html = d["content"]["raw"]
    print("judul     :", d["title"]["raw"])
    print("status    :", d["status"], "· date:", d["date"], "· date_gmt:", d["date_gmt"])
    print("slug      :", d["slug"])
    print("featured  :", d["featured_media"], "· komentar:", d["comment_status"])
    print("isi       :", len(html), "char · h2:", html.count("<h2"), "· h3:", html.count("<h3"))
    print("tombol WA :", "ada" if "wa.me/6285117444417" in html else "TIDAK ADA")
    print("em dash   :", html.count("\u2014"), "· kutip melengkung:", sum(html.count(c) for c in "\u201c\u201d\u2018\u2019"))
    print("CJK       :", sum(1 for c in html if "\u3000" <= c <= "\u9fff" or "\uac00" <= c <= "\ud7af"))
    print("strong    :", html.count("<strong"))
else:
    print(str(d)[:300])

stm, med = rest_json("GET", "/wp-json/wp/v2/media/10389?context=edit&_fields=id,source_url,alt_text,mime_type")
print("\nmedia", stm, med if not isinstance(med, dict) else
      f"#{med['id']} {med['mime_type']} alt={med['alt_text']!r}\n  {med['source_url']}")

p = xmlrpc_call("wp.getPost", [0, CFG["user"], CFG["pass"], PID])
cf = {x["key"]: x["value"] for x in p.get("custom_fields", [])}
print("\ncustom field:", len(cf))
for k in ("_yoast_wpseo_title", "_yoast_wpseo_metadesc", "_yoast_wpseo_focuskw"):
    print(f"  {k} = {cf.get(k)!r}")
