#!/usr/bin/env python3
"""Generate Herman daily CEO briefing with full activity documentation."""
from __future__ import annotations

import json
import sys
import urllib.request


def main() -> int:
    url = "http://127.0.0.1:8600/api/herman/briefing"
    req = urllib.request.Request(url, data=b"{}", headers={"Content-Type": "application/json"}, method="POST")
    try:
        with urllib.request.urlopen(req, timeout=180) as resp:
            data = json.loads(resp.read().decode("utf-8"))
        print("Herman briefing generated:", (data.get("generated_at") or "")[:19])
        print("Stats pending approvals:", (data.get("stats") or {}).get("pending_approvals"))
        return 0
    except Exception as exc:
        print("Herman briefing failed:", exc, file=sys.stderr)
        return 1


if __name__ == "__main__":
    raise SystemExit(main())
