68 lines
2.6 KiB
Python
68 lines
2.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Quick live-map verify after deploy; check API errors."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
|
|
def run(port, user, pwd, label, sudo=False):
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect("107.173.30.245", port=port, username=user, password=pwd, timeout=25)
|
|
script = r'''
|
|
import json, urllib.request, http.cookiejar, subprocess, time
|
|
print("health", urllib.request.urlopen("http://127.0.0.1:8014/api/health", timeout=5).read()[:80])
|
|
print(subprocess.getoutput("journalctl -u douyinweb-api -n 30 --no-pager | tail -30"))
|
|
cj=http.cookiejar.CookieJar()
|
|
op=urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
|
|
req=urllib.request.Request(
|
|
"http://127.0.0.1:8014/api/auth/login",
|
|
data=json.dumps({"username":"hackrobot","password":"Xiao4669805@"}).encode(),
|
|
headers={"Content-Type":"application/json"}, method="POST")
|
|
op.open(req, timeout=10)
|
|
t0=time.time()
|
|
# non-force first
|
|
try:
|
|
raw=op.open("http://127.0.0.1:8014/api/youtube/live-map", timeout=30).read()
|
|
p=json.loads(raw)
|
|
print("cache live_count", p.get("live_count"), "source", p.get("source"), "dt", round(time.time()-t0,1))
|
|
except Exception as e:
|
|
print("cache ERR", type(e).__name__, e)
|
|
t0=time.time()
|
|
try:
|
|
raw=op.open("http://127.0.0.1:8014/api/youtube/live-map?force=1", timeout=180).read()
|
|
p=json.loads(raw)
|
|
print("force live_count", p.get("live_count"), "source", p.get("source"), "dt", round(time.time()-t0,1))
|
|
for k,v in sorted((p.get("entries") or {}).items()):
|
|
if v.get("is_live"):
|
|
print(" LIVE", k, v.get("source"), (v.get("title") or "")[:40], (v.get("live_url") or "")[:60])
|
|
except Exception as e:
|
|
print("force ERR", type(e).__name__, e, "dt", round(time.time()-t0,1))
|
|
'''
|
|
if sudo:
|
|
sftp = c.open_sftp()
|
|
with sftp.file("/tmp/_qmap.py", "w") as f:
|
|
f.write(script)
|
|
sftp.close()
|
|
cmd = f"echo '{pwd}' | sudo -S -p '' python3 /tmp/_qmap.py"
|
|
stdin, stdout, stderr = c.exec_command(cmd, timeout=240)
|
|
else:
|
|
stdin, stdout, stderr = c.exec_command("python3 -", timeout=240)
|
|
stdin.write(script)
|
|
stdin.channel.shutdown_write()
|
|
print("########", label, "########")
|
|
print(stdout.read().decode("utf-8", "replace"))
|
|
err = stderr.read().decode("utf-8", "replace")
|
|
if err.strip():
|
|
print("STDERR", err[-800:])
|
|
c.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
run(22, "root", "Xiao4669805", "vps")
|
|
run(4014, "eric", "4669805", "phys", sudo=True)
|