Add a host-side Python collector that lists every bank account, pages through all ledger rows, and emits stats.json with amount_alt fields (Kilo/Mega/Peta-GOA) so large ladder withdrawals fit on the landing tiles.
40 lines
1.3 KiB
Python
Executable file
40 lines
1.3 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
"""Add amount_alt / amount_full fields to a landing stats.json in place."""
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
from goa_amounts import DEFAULT_ALT, enrich_stats_tree, load_alt_from_config # noqa: E402
|
|
|
|
|
|
def main() -> int:
|
|
ap = argparse.ArgumentParser()
|
|
ap.add_argument("path", help="stats.json path")
|
|
ap.add_argument(
|
|
"--exchange-config",
|
|
default="https://exchange.hacktivism.ch/config",
|
|
)
|
|
ap.add_argument("-o", "--out", default="", help="default: overwrite path")
|
|
args = ap.parse_args()
|
|
p = Path(args.path)
|
|
data = json.loads(p.read_text(encoding="utf-8"))
|
|
if not isinstance(data, dict) or not data.get("ok"):
|
|
print("skip: not ok stats", file=sys.stderr)
|
|
return 0
|
|
alt = load_alt_from_config(args.exchange_config) or dict(DEFAULT_ALT)
|
|
enrich_stats_tree(data, alt)
|
|
out = Path(args.out) if args.out else p
|
|
tmp = out.with_suffix(out.suffix + f".tmp.{os.getpid()}")
|
|
tmp.write_text(json.dumps(data, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
|
|
tmp.replace(out)
|
|
print(f"enriched {out}", file=sys.stderr)
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|