#!/usr/bin/env python3
"""Cek status artikel properti/manufaktur di studiosoft.id via WP REST (AUTHENTICATED, context=edit)."""
import base64, json, re, urllib.request, urllib.error

S = "https://studiosoft.id"
AUTH = base64.b64encode(b"bambangbot:q26r RePo BVy6 pwU2 F3z7 ouyl").decode()

def api(path):
    h = {"Authorization": f"Basic {AUTH}", "User-Agent": "Mozilla/5.0"}
    r = urllib.request.Request(S + path, headers=h, method="GET")
    try:
        with urllib.request.urlopen(r, timeout=120) as x:
            return x.status, json.loads(x.read())
    except urllib.error.HTTPError as e:
        return e.code, e.read().decode()[:200]
    except Exception as e:
        return 0, str(e)

IDS = [9186, 9187, 9195, 9196, 9197, 9198, 9199, 9200]
for i in IDS:
    st, d = api(f"/wp-json/wp/v2/posts/{i}?context=edit&_fields=id,slug,status,date,modified,link,title")
    if isinstance(d, dict):
        print(f"#{i} http={st} status={d.get('status'):9s} date={d.get('date')} slug={d.get('slug')}")
    else:
        print(f"#{i} http={st} -> {d}")

print("\n--- daftar posts terbaru (context=edit, status any) ---")
st, d = api("/wp-json/wp/v2/posts?per_page=20&status=any&context=edit&_fields=id,slug,status,date,title")
if isinstance(d, list):
    for p in d:
        print(f"#{p['id']:6d} {p['status']:9s} {p['date']}  {p['slug']}")
else:
    print("http", st, str(d)[:200])
