82 lines
2.8 KiB
Python
82 lines
2.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Defer due Client-B shorts uploads past cool-down; verify status."""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import sys
|
|
import http.cookiejar
|
|
import urllib.request
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
PY = r'''
|
|
import time, sys, os
|
|
os.chdir("/opt/douyinWEB/backend")
|
|
sys.path.insert(0, "/opt/douyinWEB/backend")
|
|
from app.shorts_yt_quota import (
|
|
blocked_profile_ids,
|
|
defer_profile_shorts_uploads,
|
|
profile_upload_blocked,
|
|
)
|
|
from app import db
|
|
|
|
cfg = db.get_settings_map()
|
|
for pid in ("A", "B", "C", "D"):
|
|
blocked, until = profile_upload_blocked(cfg, profile_id=pid)
|
|
if blocked or pid in ("A", "B"):
|
|
left = max(0, int((until - time.time()) / 60)) if until else 0
|
|
print(f"profile {pid} blocked={blocked} left_min={left}")
|
|
print("blocked_ids", sorted(blocked_profile_ids(cfg)))
|
|
blocked, until = profile_upload_blocked(cfg, profile_id="B")
|
|
if blocked and until > time.time():
|
|
n = defer_profile_shorts_uploads("B", until, reason="Client B 接口配额冷静,稍后自动重试")
|
|
print("deferred_B", n)
|
|
else:
|
|
print("deferred_B", 0, "(no active B cool-down)")
|
|
'''
|
|
|
|
|
|
def run(label, host, port, user, pw, *, sudo):
|
|
print(f"\n===== {label} =====")
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(host, port, user, pw, timeout=45, allow_agent=False, look_for_keys=False)
|
|
sftp = c.open_sftp()
|
|
with sftp.file("/tmp/_dy_defer_b.py", "w") as f:
|
|
f.write(PY.replace("\r\n", "\n"))
|
|
sftp.close()
|
|
py = "/opt/douyinWEB/backend/.venv/bin/python /tmp/_dy_defer_b.py"
|
|
cmd = f"echo '{pw}' | sudo -S -p '' {py}" if sudo else py
|
|
_, o, e = c.exec_command(cmd, timeout=120)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"))
|
|
c.close()
|
|
|
|
|
|
def pub(base):
|
|
cj = http.cookiejar.CookieJar()
|
|
op = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
|
|
data = json.dumps({"username": "hackrobot", "password": "Xiao4669805@"}).encode()
|
|
req = urllib.request.Request(
|
|
base + "/api/auth/login", data=data, method="POST", headers={"Content-Type": "application/json"}
|
|
)
|
|
op.open(req, timeout=30)
|
|
with op.open(urllib.request.Request(base + "/api/shorts/status"), timeout=40) as r:
|
|
st = json.loads(r.read().decode())
|
|
print(
|
|
base,
|
|
"blocked=", st.get("upload_quota_blocked"),
|
|
"profiles=", st.get("upload_quota_blocked_profiles"),
|
|
"cooldown_sec=", st.get("yt_quota_cooldown_sec"),
|
|
"uploads=", st.get("active_uploads"),
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
run("VPS dylive", "107.173.30.245", 22, "root", "Xiao4669805", sudo=False)
|
|
run("phys dy", "107.173.30.245", 4014, "eric", "4669805", sudo=True)
|
|
print("\n===== public =====")
|
|
pub("https://dylive.nomadro.com")
|
|
pub("https://dy.nomadro.com")
|