#!/usr/bin/env python3
"""TSLaw: cek tampilan draft #3532 lewat URL preview (butuh login) — HTML jadi, bukan raw REST."""
import base64, re, urllib.request, urllib.error

DOM = "www.tslaw.id"
AUTH = base64.b64encode(b"bambangbot:EFKm EYGx VQCP Y9go ncPr uM2Y").decode()
UA = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/124 Safari/537.36",
      "Authorization": f"Basic {AUTH}"}
URL = "https://www.tslaw.id/?p=3532&preview=true"

try:
    with urllib.request.urlopen(urllib.request.Request(URL, headers=UA), timeout=180) as x:
        html = x.read().decode("utf-8", "replace")
        code = x.status
except urllib.error.HTTPError as e:
    html, code = e.read().decode("utf-8", "replace"), e.code

print(f"HTTP {code} | {len(html)} byte")
t = re.search(r"<title>(.*?)</title>", html, re.S)
print(f"title     : {t.group(1).strip()[:120] if t else '(tidak ada)'}")
d = re.search(r'<meta name="description" content="(.*?)"', html, re.S)
print(f"meta desc : {d.group(1)[:170] if d else '(tidak ada)'}")
og = re.search(r'<meta property="og:image" content="(.*?)"', html, re.S)
print(f"og:image  : {og.group(1) if og else '(tidak ada)'}")
lebar1000 = 'width="1000"' in html
print(f"featured  : {'wp-post-image' in html} | lebar 1000: {lebar1000}")
print(f"h1        : {re.findall(r'<h1[^>]*>(.*?)</h1>', html, re.S)[:1]}")
print(f"h2 jumlah : {len(re.findall(r'<h2', html))}")
print(f"wa.me     : {'wa.me/6281909222026' in html}")
print(f"FAQPage   : {'FAQPage' in html}")
print(f"viewport  : {'width=device-width' in html}")
ph = re.findall(r"\{[A-Za-z_0-9\[\]]+\}", html)
print(f"placeholder: {len(ph)}")
