#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Dump utuh 1 akun Repliz (cek status sambungan, mis. LinkedIn TS Law)."""
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

ACC = sys.argv[1]
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

for x in docs:
    if (x.get("_id") or x.get("id")) == ACC:
        print(json.dumps(x, indent=1, ensure_ascii=False))
