douyinWEB/scripts/_diag_quota_progress_facts.py
2026-09-13 22:10:49 -05:00

73 lines
2.8 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Compare yt-long board used vs uploaded + Google quota facts on dy/dylive."""
from __future__ import annotations
import sys
import time
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
PASS = "Xiao4669805"
HOSTS = [("dy", "108.174.50.68"), ("dylive", "107.173.30.245")]
REMOTE = r'''
cd /opt/douyinWEB/backend
.venv/bin/python <<'PY'
import json
from app import db, yt_long_db
from app.shorts_yt_quota import quota_budgets_by_profile, yt_daily_limit, _load_quota_map
from app.timeutil import push_date_from_ts, pacific_day_from_ts
import time
cfg = db.get_settings_map()
day = push_date_from_ts(time.time())
print("bj_day", day, "pt_day", pacific_day_from_ts(time.time()))
print("shorts_yt_daily_upload_limit", cfg.get("shorts_yt_daily_upload_limit"), "fn", yt_daily_limit(cfg))
print("yt_long_daily_max", cfg.get("yt_long_daily_max"), "channel_daily", cfg.get("yt_long_channel_daily_max"))
print("limited_day", cfg.get("yt_long_quota_limited_day"), "reason", str(cfg.get("yt_long_quota_limited_reason") or "")[:180])
print("quota_map", json.dumps(_load_quota_map(cfg), ensure_ascii=False)[:900])
print("budgets", json.dumps(quota_budgets_by_profile(cfg), ensure_ascii=False)[:1500])
board = yt_long_db.channel_board(day)
chs = board.get("channels") or []
print("yt_long_channels", len(chs), "upload_used", yt_long_db.yt_long_upload_used(day), "daily_max", yt_long_db.yt_long_daily_max(cfg))
weird = []
for c in chs:
u, up, dmax = int(c.get("used") or 0), int(c.get("uploaded") or 0), int(c.get("daily_max") or 0)
if u != up or (c.get("enabled") and (u or up)):
weird.append((c.get("name"), "used", u, "uploaded", up, "sched", c.get("scheduled"), "pend", c.get("pending"), "dmax", dmax, "en", c.get("enabled")))
print("nonzero_or_mismatch", len(weird))
for row in weird[:20]:
print(" ", row)
s = db.shorts_channels_quota_summary(day)
print("shorts_n", len(s), "uploaded_sum", sum(int(r.get("uploaded") or 0) for r in s), "used_sum", sum(int(r.get("used") or 0) for r in s))
# show statuses that count as used for yt-long
from app.yt_long_db import _UPLOAD_STATUSES
print("YT_LONG_UPLOAD_STATUSES", _UPLOAD_STATUSES)
PY
'''
def run(host: str) -> str:
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
for i in range(6):
try:
c.connect(host, 22, "root", PASS, timeout=35, allow_agent=False, look_for_keys=False)
break
except Exception as e:
print(f"ssh_retry {host} {i}: {e}", flush=True)
time.sleep(2)
else:
return "ssh_fail"
_, o, e = c.exec_command(REMOTE, timeout=70)
out = (o.read() + e.read()).decode("utf-8", "replace")
c.close()
return out
for label, host in HOSTS:
print(f"\n==== {label} {host} ====", flush=True)
print(run(host), flush=True)