#!/usr/bin/env python3
"""Cari slug nyata untuk tautan internal calon artikel schema lokal."""
import base64, json, re, time, urllib.error, urllib.parse, 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(path):
    for i in range(3):
        try:
            r = urllib.request.Request(f"https://{DOM}{path}", headers=h)
            with urllib.request.urlopen(r, timeout=180) as x:
                return json.loads(x.read())
        except Exception:
            time.sleep(4)
    return None


for kw in ("kata kunci lokal", "google business profile", "peta", "ulasan google", "seo lokal"):
    d = get(f"/wp-json/wp/v2/posts?search={urllib.parse.quote(kw)}&per_page=10&status=publish&_fields=id,slug,title")
    print(f"== {kw} ==")
    for p in (d or []):
        print(f"   #{p['id']:5d} {p['slug'][:75]}")
