#!/usr/bin/env python3
"""TSLaw: verifikasi cepat — alamat lama, alamat baru, dan tautan di dua artikel baru."""
import re, urllib.request, urllib.error

UA = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/124 Safari/537.36"}


def cek(u):
    try:
        r = urllib.request.urlopen(urllib.request.Request(f"https://www.tslaw.id{u}", headers=UA), timeout=60)
        return r.status, r.read().decode("utf-8", "replace"), r.geturl()
    except urllib.error.HTTPError as e:
        return e.code, "", e.headers.get("Location", "")
    except Exception as e:
        return 0, "", str(e)[:60]


print("=== alamat lama & baru ===")
for u in ("/practice-areas/", "/layanan/"):
    st, h, info = cek(u)
    t = re.search(r"<title>(.*?)</title>", h, re.S) if h else None
    print(f"   {u:<20} HTTP {st} | {'dialihkan ke ' + info if info else ''} {t.group(1)[:44] if t else ''}")

print("\n=== tautan di artikel baru ===")
for u in ("/pengacara-gugat-cerai-surabaya/", "/pengacara-surat-wasiat/"):
    st, h, _ = cek(u)
    ke_beranda = h.count('href="https://www.tslaw.id/"')
    print(f"   {u}")
    print(f"      /layanan/ {h.count('/layanan/')}x | /practice-areas/ {h.count('practice-areas')}x | "
          f"ke beranda {ke_beranda}x")
