81 lines
2.2 KiB
Python
81 lines
2.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Blank missing avatar_url so UI falls back to /api/sessions/.../cover."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import time
|
|
import urllib.request
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
HOSTS = [("dylive", "107.173.30.245"), ("dy", "108.174.50.68")]
|
|
PASS = "Xiao4669805"
|
|
|
|
|
|
def connect(host):
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
for i in range(8):
|
|
try:
|
|
c.connect(host, 22, "root", PASS, timeout=40, allow_agent=False, look_for_keys=False, banner_timeout=120)
|
|
return c
|
|
except Exception as e:
|
|
print("retry", host, e, flush=True)
|
|
time.sleep(2 + i)
|
|
raise SystemExit("ssh fail")
|
|
|
|
|
|
SCRIPT = r"""
|
|
cd /opt/douyinWEB/backend
|
|
./.venv/bin/python - <<'PY'
|
|
from app.db import _connect, _lock
|
|
import urllib.request
|
|
|
|
def exists(url: str) -> bool:
|
|
try:
|
|
urllib.request.urlopen(url, timeout=4).read(8)
|
|
return True
|
|
except Exception:
|
|
return False
|
|
|
|
with _lock:
|
|
conn = _connect()
|
|
rows = conn.execute(
|
|
"SELECT id, avatar_url FROM rooms WHERE avatar_url IS NOT NULL AND avatar_url != ''"
|
|
).fetchall()
|
|
cleared = kept = 0
|
|
for rid, u in rows:
|
|
u = str(u or "").strip()
|
|
if not u.startswith("http"):
|
|
continue
|
|
if exists(u):
|
|
kept += 1
|
|
continue
|
|
conn.execute("UPDATE rooms SET avatar_url='' WHERE id=?", (rid,))
|
|
cleared += 1
|
|
# pool covers pointing at dead hosts
|
|
try:
|
|
for a in (
|
|
"https://dy.nomadro.com/douyin-covers%",
|
|
):
|
|
cur = conn.execute(
|
|
"UPDATE yt_assign_pool_urls SET cover_url='' WHERE cover_url LIKE ?",
|
|
(a,),
|
|
)
|
|
print("pool_cleared_dycom", cur.rowcount)
|
|
except Exception as e:
|
|
print("pool", e)
|
|
conn.commit()
|
|
print("avatar_kept", kept, "avatar_cleared", cleared)
|
|
PY
|
|
"""
|
|
|
|
for label, host in HOSTS:
|
|
print(f"######## {label} ########", flush=True)
|
|
c = connect(host)
|
|
_i, o, e = c.exec_command(SCRIPT, timeout=300)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"), flush=True)
|
|
c.close()
|
|
print("ALL_DONE", flush=True)
|