feat(stove-api): expose estimate and operator controls
This commit is contained in:
+17
-2
@@ -70,11 +70,17 @@ def collect(hours: int = 24) -> dict:
|
||||
"broken_users": sorted({r[0] for r in broken}),
|
||||
}
|
||||
out["topups"] = _topups(since)
|
||||
try:
|
||||
import stove_api_digest
|
||||
out["stove_api"] = stove_api_digest.collect(hours)
|
||||
except sqlite3.Error:
|
||||
out["stove_api"] = None
|
||||
t = out["topups"]
|
||||
# Cron sends with --quiet-ok and decides by this flag: a day of payments is not quiet.
|
||||
out["quiet"] = (out["broken_runs"] == 0 and out["masked_errors"] == 0
|
||||
and out["feedback"] == 0
|
||||
and not (t["count"] or t["refunds"] or t["unpaid"]))
|
||||
and not (t["count"] or t["refunds"] or t["unpaid"])
|
||||
and not (out["stove_api"] and out["stove_api"]["total"]))
|
||||
return out
|
||||
|
||||
|
||||
@@ -105,7 +111,8 @@ def render(d: dict) -> str:
|
||||
head = f"📊 smeta-web за {d['hours']} ч"
|
||||
t = d.get("topups") or {"count": 0, "kop": 0, "refunds": 0, "unpaid": 0}
|
||||
if (d["quiet"] and not d["active_users"] and not d["registrations"]
|
||||
and not (t["count"] or t["refunds"] or t["unpaid"])):
|
||||
and not (t["count"] or t["refunds"] or t["unpaid"])
|
||||
and not (d.get("stove_api") or {}).get("total")):
|
||||
return f"{head}: тихо — живых обращений не было."
|
||||
lines = [
|
||||
head + ":",
|
||||
@@ -119,6 +126,9 @@ def render(d: dict) -> str:
|
||||
f"• Пополнений за сутки: {t['count']} на {_rub(t['kop'])}; "
|
||||
f"возвратов {t['refunds']}; неоплаченных {t['unpaid']}",
|
||||
]
|
||||
if d.get("stove_api"):
|
||||
import stove_api_digest
|
||||
lines.append(stove_api_digest.render(d["stove_api"]))
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
@@ -132,6 +142,11 @@ if __name__ == "__main__":
|
||||
help="не слать, если день прошёл тихо")
|
||||
args = ap.parse_args()
|
||||
|
||||
try:
|
||||
import stove_cleanup
|
||||
stove_cleanup.cleanup()
|
||||
except sqlite3.Error:
|
||||
pass
|
||||
data = collect(args.hours)
|
||||
text = render(data)
|
||||
print(text)
|
||||
|
||||
Reference in New Issue
Block a user