#!/usr/bin/env python3
"""Verifikasi halaman publik tslaw.id post 3234 setelah perbaikan 2026-10-10."""
import html as htmlmod, json, re, urllib.request

URL = "https://www.tslaw.id/cara-daftar-cv-pt-online/"
HDR = {"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 Chrome/120 Safari/537.36",
       "Cache-Control": "no-cache"}


def ambil(url):
    req = urllib.request.Request(url, headers=HDR)
    with urllib.request.urlopen(req, timeout=120) as r:
        return r.status, r.read().decode("utf-8", "replace")


hasil = {}
for label, url in (("normal", URL), ("cache buster", URL + "?v=20261010b")):
    st, body = ambil(url)
    # batasi ke area artikel (schema/header ikut terhitung kalau tidak dipotong)
    m = re.search(r'<div[^>]+class="[^"]*entry-content[^"]*"', body)
    isi = body[m.start():] if m else body
    teks = htmlmod.unescape(re.sub(r"<(script|style).*?</\1>", " ", isi, flags=re.S))
    hasil[label] = {
        "http": st,
        "title_tag": (re.search(r"<title>(.*?)</title>", body, re.S) or [None, ""])[1].strip()[:120],
        "meta_desc": (re.search(r'<meta name="description" content="(.*?)"', body) or [None, ""])[1][:200],
        "h1": [re.sub(r"<[^>]+>", "", h).strip() for h in re.findall(r"<h1[^>]*>(.*?)</h1>", body, re.S)][:3],
        "kata_isi_artikel": len(re.sub(r"<[^>]+>", " ", teks).split()),
        "kewajiban_live": "Kewajiban Setelah Badan Usaha Berdiri" in body,
        "ditolak_live": "Penyebab Pendaftaran CV atau PT Ditolak" in body,
        "tender_live": "CV atau PT untuk Tender dan Kredit Bank" in body,
        "sendiri_live": "Bagian Mana yang Bisa Dikerjakan Sendiri" in body,
        "faq_lama_utuh": body.count("rank-math-faq-question") >= 5,
        "faqpage_schema_live": body.count('"@type": "FAQPage"'),
        "tombol_wa_live": body.count("wa.me/6281909222026"),
        "h2_live": len(re.findall(r"<h2", isi)),
        "judul_tidak_berubah": "Cara Daftar CV dan PT Online" in body,
    }
    print(f"=== {label} ({url})")
    print(json.dumps(hasil[label], ensure_ascii=False, indent=1))

json.dump(hasil, open("/home/mantapman/.hermes/profiles/atun/workspace/tslaw_pemulihan/"
                      "perbaikan_20261010/live_3234_verifikasi.json", "w"),
          ensure_ascii=False, indent=1)
