#!/usr/bin/env python3
"""Verifikasi live post 3232 tslaw.id setelah perbaikan 2026-10-09 (HTML publik)."""
import json, re, time, urllib.request

URL = f"https://www.tslaw.id/panduan-cerai-gugat/?nocache={int(time.time())}"
req = urllib.request.Request(URL, headers={"User-Agent": "Mozilla/5.0 (X11; Linux x86_64)"})
with urllib.request.urlopen(req, timeout=120) as r:
    html = r.read().decode("utf8", "ignore")
    print("HTTP", r.status, "| cf-cache:", r.headers.get("cf-cache-status"),
          "| x-cache:", r.headers.get("x-cache"), "| bytes:", len(html))

judul = re.search(r"<title>(.*?)</title>", html, re.S)
desc = re.search(r'<meta name="description" content="(.*?)"', html, re.S)
h1 = [re.sub(r"<[^>]+>", "", x).strip() for x in re.findall(r"<h1[^>]*>(.*?)</h1>", html, re.S)]
teks = re.sub(r"<(script|style).*?</\1>", " ", html, flags=re.S)
teks = re.sub(r"<[^>]+>", " ", teks)

hasil = {
    "http": 200,
    "title_tag": judul.group(1).strip() if judul else None,
    "meta_desc": desc.group(1).strip() if desc else None,
    "h1": h1[:3],
    "bagian_perbandingan_live": "Cerai Gugat dan Cerai Talak: Letak Perbedaannya" in html,
    "bagian_waktu_biaya_live": "Berapa Lama dan Berapa Biaya Cerai Gugat?" in html,
    "bagian_online_live": "Bisakah Cerai Gugat Diajukan Online?" in html,
    "bagian_kendala_live": "Yang Membuat Gugatan Cerai Berlarut-larut" in html,
    "faq_lama_utuh": "Apakah bisa cerai gugat tanpa sidang?" in html,
    "tombol_wa_live": html.count("wa.me/6281909222026"),
    "faqpage_live": html.count("FAQPage"),
    "tautan_pilar_live": html.count("law-firm-surabaya"),
    "judul_masih_lama": "Panduan Cerai Gugat: Syarat, Biaya, dan Prosedur Lengkap 2026" in html,
}
print()
for k, v in hasil.items():
    print(f"  {k}: {v}")
json.dump(hasil, open("/home/mantapman/.hermes/profiles/atun/workspace/tslaw_pemulihan/"
                      "perbaikan_20261009/live_3232_verifikasi.json", "w"),
          ensure_ascii=False, indent=1)
