#!/usr/bin/env python3
"""Kembalikan 7 artikel StudioSoft ke status terjadwal (future) memakai tanggal yang sudah tersimpan.

Tanpa AI, tanpa menulis ulang isi — cukup ubah status supaya WordPress yang menerbitkan sendiri.
"""
import base64, json, time, urllib.request

S = "https://studiosoft.id"
H = {"Authorization": "Basic " + base64.b64encode(b"bambangbot:q26r RePo BVy6 pwU2 F3z7 ouyl").decode(),
     "User-Agent": "Mozilla/5.0", "Content-Type": "application/json"}
PID = [9315, 9319, 9322, 9332, 9335, 9393, 9402]


def rest(p, method="GET", data=None):
    body = json.dumps(data).encode() if data is not None else None
    r = urllib.request.Request(S + p, data=body, headers=H, method=method)
    with urllib.request.urlopen(r, timeout=180) as x:
        return json.loads(x.read())


print("sebelum:")
for pid in PID:
    d = rest(f"/wp-json/wp/v2/posts/{pid}?context=edit&_fields=status,date,slug")
    print(f"   #{pid} {d['status']:<7} {d['date'][:16]} {d['slug'][:44]}")

print("\nmenjadwalkan:")
for pid in PID:
    d = rest(f"/wp-json/wp/v2/posts/{pid}?context=edit&_fields=date")
    rest(f"/wp-json/wp/v2/posts/{pid}", "POST", {"status": "future", "date": d["date"]})
    time.sleep(0.5)
    v = rest(f"/wp-json/wp/v2/posts/{pid}?context=edit&_fields=status,date,featured_media,slug")
    print(f"   #{pid} {v['status']:<7} {v['date'][:16]} gambar {v['featured_media']} {v['slug'][:40]}")

f = rest("/wp-json/wp/v2/posts?per_page=20&status=future&orderby=date&order=asc&_fields=id,date,featured_media")
print(f"\nantrean sekarang: {len(f)} artikel")
for x in f:
    print(f"   {x['date'][:10]} gambar {x.get('featured_media') or '-'} #{x['id']}")
