#!/usr/bin/env python3
"""Verifikasi hasil perbaikan DAS: cek meta & konten lewat context=edit + live page."""
import base64, json, re, urllib.request

SITE = "https://dasindonesia.com"
AUTH = base64.b64encode(b"bambangbot:u3a1 G2pQ 3SWY f0zI OlGP YAjU").decode()
IDS = [5552, 5569, 5609, 5657, 5684, 5705, 6304, 6420, 6566, 6705, 6708, 6711, 6772]


def api(p):
    r = urllib.request.Request(SITE + p, headers={"Authorization": f"Basic {AUTH}", "User-Agent": "Mozilla/5.0"})
    with urllib.request.urlopen(r, timeout=240) as x:
        return json.loads(x.read())


print(f"{'id':>6} {'fk di WP':<32} {'meta':>5} {'title SEO':>10} {'Baca Juga':>10}  meta awal")
for pid in IDS:
    p = api(f"/wp-json/wp/v2/posts/{pid}?context=edit&_fields=id,link,meta,content")
    m = p["meta"]
    fk = m.get("_yoast_wpseo_focuskw", "")
    md = m.get("_yoast_wpseo_metadesc", "")
    tt = m.get("_yoast_wpseo_title", "")
    bj = "ADA" if "Baca Juga" in p["content"]["raw"] else "-"
    print(f"{pid:>6} {fk[:30]:<32} {len(md):>5} {len(tt):>10} {bj:>10}  {md[:70]}")
