import json, os, sys src = os.environ.get("SOUZ_BANK", "souz_bank.jsonl") dst = os.environ.get("SOUZ_KEYS", "keys.jsonl") seen, out = set(), [] for line in open(src, encoding="utf-8"): try: r = json.loads(line) except Exception: continue if not r.get("ok"): continue bal = (r.get("balance") or {}).get("available_micro") or 0 k = (r.get("key") or {}).get("key") or "" if bal <= 0 or not k or k in seen: continue seen.add(k) out.append({"key": k, "user": (r.get("tg") or {}).get("tg_id"), "bal": bal}) lines = [json.dumps(x, ensure_ascii=False) for x in out] NL = chr(10) open(dst, "w", encoding="utf-8").write(NL.join(lines) + NL) print("synced", len(out))