#!/usr/bin/env python3
"""Ambil 5 artikel terakhir StudioSoft + cari warna primary situs + nomor WhatsApp yang dipakai."""
import base64, html, json, re, urllib.request

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


def wp(path):
    r = urllib.request.Request(S + path, headers={"Authorization": f"Basic {AUTH}", "User-Agent": "Mozilla/5.0"})
    return json.loads(urllib.request.urlopen(r, timeout=200).read())


print("=== 5 ARTIKEL TERAKHIR ===")
d = wp("/wp-json/wp/v2/posts?per_page=5&context=edit&_fields=id,slug,title,date,link,content")
for p in d:
    raw = p["content"]["raw"] if isinstance(p["content"], dict) else ""
    print(f"  #{p['id']} {p['date'][:10]} | {html.unescape(p['title']['rendered'])[:66]}")
    print(f"      {p['link']}")
    print(f"      panjang {len(raw)} char | sudah ada tombol WA blok: {'konsultasi gratis' in raw.lower()}")

print("\n=== WARNA PRIMARY & NOMOR WA dari halaman utama ===")
r = urllib.request.Request(S + "/", headers={"User-Agent": "Mozilla/5.0"})
h = urllib.request.urlopen(r, timeout=90).read().decode("utf-8", "replace")
for m in re.findall(r"--ast-global-color-\d:\s*#[0-9a-fA-F]{3,8}", h):
    print("  ", m)
for m in sorted(set(re.findall(r"wa\.me/(\d+)", h))):
    print("   wa.me nomor:", m)
btn = re.findall(r'<a[^>]*class="[^"]*(?:button|btn)[^"]*"[^>]*>', h)[:6]
for b in btn:
    print("   contoh tombol:", b[:170])
