#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Cari artikel tslaw.id yang bersinggungan topik tanah waris (cegah kanibalisasi)."""
import json
import sys

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

CARI = ["tanah waris", "waris", "jual beli tanah", "sertifikat", "ahli waris", "pertanahan"]

for kw in CARI:
    try:
        hasil = T.posts(per_page=20, search=kw, status="publish,future,draft",
                        _fields="id,slug,title,date,status,link")
    except Exception as e:
        print(f"[{kw}] GAGAL: {e}")
        continue
    print(f"\n=== '{kw}' → {len(hasil)} artikel ===")
    for p in hasil:
        print(f"  #{p['id']} [{p.get('status','?')}] {p['date'][:10]} | {p['title']['rendered'][:70]}")
        print(f"        {p['link']}")

print("\n=== semua kategori ===")
try:
    for c in T.kategori():
        print(f"  #{c['id']} {c['name']} ({c['count']})")
except Exception as e:
    print("GAGAL kategori:", e)
