#!/usr/bin/env python3
"""Verifikasi akhir: status jadwal #9997, media, dan halaman live belum tayang."""
import base64, json, re, time, urllib.error, urllib.request

DOM = "studiosoft.id"
AUTH = base64.b64encode(b"bambangbot:q26r RePo BVy6 pwU2 F3z7 ouyl").decode()
h = {"Authorization": f"Basic {AUTH}", "User-Agent": "Mozilla/5.0"}


def get(p):
    for i in range(3):
        try:
            r = urllib.request.Request(f"https://{DOM}{p}", headers=h)
            with urllib.request.urlopen(r, timeout=180) as x:
                return x.status, json.loads(x.read())
        except urllib.error.HTTPError as e:
            return e.code, e.read().decode()[:200]
        except Exception:
            time.sleep(4)
    return 0, "gagal"


st, p = get("/wp-json/wp/v2/posts/9997?context=edit&_fields=id,slug,status,date,date_gmt,link,title,content,featured_media,meta,categories")
raw = p["content"]["raw"]
print(f"#{p['id']} status={p['status']} date={p['date']} gmt={p['date_gmt']}")
print(f"slug={p['slug']} kategori={p['categories']} media={p['featured_media']}")
CJK = len(re.findall(r"[\u3000-\u9fff\uac00-\ud7af]", raw))
print(f"kata={len(re.sub('<[^>]+>', ' ', raw).split())} · em dash={raw.count(chr(8212))} · CJK={CJK}")
print(f"tautan: {sorted(set(re.findall(r'https://studiosoft.id/[a-z0-9-]+/', raw)))}")
st, m = get("/wp-json/wp/v2/media/9998?_fields=id,source_url,media_type,mime_type,alt_text")
print(f"media: {m['source_url']} · {m['mime_type']} · alt='{m['alt_text']}'")
st, d = get("/wp-json/wp/v2/posts?status=future&per_page=100&orderby=date&order=asc&_fields=id,date")
print("jadwal:", [f"{x['date'][:10]}#{x['id']}" for x in d])
