48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Освежает баланс/Theos по всем аккаунтам банка и дописывает обновлённые записи.
|
|
|
|
python refresh_balances.py [--write]
|
|
Без --write только печатает статистику.
|
|
"""
|
|
import json
|
|
import sys
|
|
import time
|
|
|
|
import dpcode as D
|
|
|
|
write = "--write" in sys.argv
|
|
recs = [r for r in D.read_bank() if r.get("cookies")]
|
|
total = 0.0
|
|
live = 0
|
|
rows = []
|
|
for r in recs:
|
|
email = r["email"]
|
|
machine = r.get("machine") or D.machine_header(salt=email)
|
|
s = D.session_from(r)
|
|
st, body = D.theos(s, machine)
|
|
bal = 0.0
|
|
if st == 200 and isinstance(body, dict):
|
|
try:
|
|
bal = float(body.get("balance") or 0)
|
|
except Exception:
|
|
bal = 0.0
|
|
r["theos_status"] = st
|
|
r["theos"] = body
|
|
r["machine"] = machine
|
|
r["ok"] = bool(body.get("enabled")) and bal > 0
|
|
if bal > 0:
|
|
live += 1
|
|
total += bal
|
|
if write:
|
|
D.append_bank(r)
|
|
rows.append((email, st, bal))
|
|
time.sleep(0.15)
|
|
|
|
print(f"accounts={len(recs)} live_with_balance={live} total_theos={round(total,2)}")
|
|
for email, st, bal in sorted(rows, key=lambda x: -x[2])[:5]:
|
|
print(f" {email[:40]:40s} {st} {bal}")
|
|
low = [r for r in rows if r[2] <= 0]
|
|
print("zero_balance:", len(low))
|
|
if low[:3]:
|
|
for e, st, b in low[:3]:
|
|
print(" zero:", e, st, b) |