#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Bahan sebelum menulis artikel tslaw.id: tag yang relevan, tautan internal hidup, nomor WA di situs."""
import json
import re
import subprocess
import sys

sys.path.insert(0, "/home/mantapman/.hermes/profiles/atun/workspace")
import tslaw_wp as T  # noqa: E402

print("=== nama tag untuk id yang dipakai artikel tanah/waris ===")
ids = [9, 55, 38, 54, 87, 35, 40, 37, 36, 39, 41, 46, 111, 112, 77, 79, 78, 76]
try:
    r = T.get("tags", {"include": ",".join(map(str, ids)), "per_page": 100, "_fields": "id,name,slug,count"})
    for t in sorted(r.json(), key=lambda x: -x["count"]):
        print(f"  {t['id']:4} {t['name'][:40]:42} slug={t['slug'][:32]:34} dipakai {t['count']}x")
except Exception as e:
    print("GAGAL ambil tag:", e)

print("\n=== tautan internal (harus 200) ===")
TAUTAN = [
    "https://www.tslaw.id/7-langkah-aman-jual-beli-tanah-secara-hukum-agar-tidak-sengketa-di-kemudian-hari/",
    "https://www.tslaw.id/6-langkah-mengurus-warisan-tanpa-sengketa-keluarga/",
    "https://www.tslaw.id/warisan-dan-hibah-perbedaan-syarat-cara-mengurus/",
    "https://www.tslaw.id/6-langkah-mengurus-sengketa-tanah-secara-hukum-di-indonesia/",
    "https://www.tslaw.id/cara-mengurus-sertifikat-tanah/",
    "https://www.tslaw.id/pengacara-surat-wasiat/",
]
for u in TAUTAN:
    r = subprocess.run(["curl", "-4", "-s", "-o", "/dev/null", "-w", "%{http_code}",
                        "--max-time", "60", "-L", u], capture_output=True, text=True)
    print(f"  {r.stdout.strip()}  {u}")

print("\n=== nomor WA yang tampil di situs (halaman depan) ===")
r = subprocess.run(["curl", "-4", "-s", "--max-time", "90", "-L", "https://www.tslaw.id/"],
                   capture_output=True, text=True)
html = r.stdout
for pat in (r"wa\.me/(\d+)", r"62\d{8,13}", r"08\d{2}[- ]?\d{3,4}[- ]?\d{3,5}"):
    temuan = sorted(set(re.findall(pat, html)))
    print(f"  pola {pat}: {temuan[:6]}")
