#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Probe room 369511597884 live status on VPS vs monitor badge.""" import json import sys import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") SH = r""" cd /opt/douyinWEB/backend || cd /root/douyinWEB/backend || true python3 - <<'PY' import json, sqlite3 from pathlib import Path # find monitor.db cands = list(Path('/opt/douyinWEB').rglob('monitor.db')) + list(Path('/root').rglob('monitor.db')) if Path('/root').exists() else list(Path('/opt/douyinWEB').rglob('monitor.db')) print('dbs', [str(p) for p in cands[:5]]) db = None for p in cands: if 'douyinWEB' in str(p) and 'backend' in str(p): db = p; break if not db and cands: db = cands[0] print('using', db) room = '369511597884' con = sqlite3.connect(f'file:{db}?mode=ro', uri=True) con.row_factory = sqlite3.Row cur = con.cursor() cur.execute("select room_id, url, note, last_status, last_anchor, last_title, last_checked_at, last_error from rooms where room_id=? or url like ?", (room, f'%{room}%')) rows = [dict(r) for r in cur.fetchall()] print('monitor_rooms', json.dumps(rows, ensure_ascii=False, default=str)) # live probe via app import sys sys.path.insert(0, str(Path(db).resolve().parents[1] / 'app') if False else '/opt/douyinWEB/backend') sys.path.insert(0, '/opt/douyinWEB/backend') try: from app import douyin r = douyin.probe_live(f'https://live.douyin.com/{room}') print('probe', json.dumps({k:r.get(k) for k in ('ok','is_live','status','status_code','anchor','title','error','risk') if k in r or True}, ensure_ascii=False, default=str)[:800]) print('probe_keys', sorted(r.keys())[:30]) print('is_live', r.get('is_live'), 'status_code', r.get('status_code') or r.get('status')) except Exception as e: print('probe_err', type(e).__name__, e) # relay state for nomadvlog cur.execute("select name from sqlite_master where type='table' and name like '%relay%'") print('relay_tables', [r[0] for r in cur.fetchall()]) try: cur.execute("select group_id, status, source_url, detail, updated_at from yt_relay_states") for row in cur.fetchall(): d = dict(row) if hasattr(row, 'keys') else None if d is None: print(row) else: print('state', json.dumps(d, ensure_ascii=False, default=str)[:300]) except Exception as e: print('states_err', e) con.close() PY """ def main() -> None: c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # VPS direct c.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=40, allow_agent=False, look_for_keys=False) sftp = c.open_sftp() with sftp.file("/tmp/_probe_room_live.sh", "wb") as f: f.write(SH.encode()) sftp.close() _i, o, e = c.exec_command("bash /tmp/_probe_room_live.sh", timeout=90) print((o.read() + e.read()).decode("utf-8", "replace")) c.close() if __name__ == "__main__": main()