#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Daftar akun Repliz (username, platform, id) — untuk cek akun TS Law mana saja yang aktif."""
import json
import sys
import urllib.parse
import urllib.request

sys.path.insert(0, "/home/mantapman/.hermes/profiles/atun/workspace")
from repliz_client import HEADERS, BASE  # noqa: E402

docs, page = [], 1
while True:
    q = urllib.parse.urlencode({"page": page, "limit": 100})
    req = urllib.request.Request(f"{BASE}/public/account?{q}", headers=HEADERS)
    with urllib.request.urlopen(req, timeout=60) as r:
        d = json.load(r)
    docs += d.get("docs", d.get("data", []))
    if not d.get("hasNextPage") or not docs:
        break
    page += 1

print(f"total akun: {len(docs)}")
kata = ("tito", "tslaw", "ts_law", "lawfirm", "law")
for x in sorted(docs, key=lambda z: (str(z.get("type")), str(z.get("username")))):
    u = str(x.get("username") or "")
    if any(k in u.lower() for k in kata):
        print(f"{x.get('type'):12s} | @{u:32s} | id={x.get('_id') or x.get('id')} | "
              f"status={x.get('status') or x.get('isActive')}")
