douyinWEB/scripts/_inspect_shorts_oauth_now.py
eric d409e416da Ship physical dual-edge stack, Studio CDP live metrics, and ops tooling.
Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-04 22:42:40 -05:00

44 lines
1.9 KiB
Python

# -*- coding: utf-8 -*-
import paramiko
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=30, allow_agent=False, look_for_keys=False)
script = r"""
import json, sqlite3, time
conn = sqlite3.connect('/opt/douyinWEB/backend/data/monitor.db')
conn.row_factory = sqlite3.Row
cur = conn.cursor()
cur.execute("SELECT key, value FROM kv_settings WHERE key IN ('shorts_enabled','yt_long_enabled','notify_on_shorts_fail')")
for r in cur.fetchall():
print(r[0], r[1])
cur.execute('''SELECT id, name, enabled, oauth_ok, oauth_error, oauth_profile_id,
youtube_channel_id, CASE WHEN refresh_token IS NOT NULL AND length(refresh_token)>0 THEN 1 ELSE 0 END AS has_rt
FROM shorts_channels ORDER BY enabled DESC, name''')
rows = [dict(r) for r in cur.fetchall()]
bad = [r for r in rows if r.get('enabled') and (int(r.get('oauth_ok') or 0) != 1)]
print('enabled_channels', sum(1 for r in rows if r.get('enabled')))
print('oauth_bad', len(bad))
for r in bad:
print('BAD |', r.get('name'), '|', (r.get('oauth_error') or '')[:100], '| profile', r.get('oauth_profile_id'))
cur.execute("SELECT kind, message, ts FROM events WHERE kind='shorts_fail' ORDER BY ts DESC LIMIT 6")
for r in cur.fetchall():
print('EVENT |', time.strftime('%Y-%m-%d %H:%M', time.localtime(r[2])), '|', r[1][:150])
ok = [r for r in rows if r.get('enabled') and int(r.get('oauth_ok') or 0) == 1]
print('oauth_ok', len(ok))
for r in ok:
print('OK |', r.get('name'), '| profile', r.get('oauth_profile_id'))
conn.close()
"""
sftp = c.open_sftp()
with sftp.file("/tmp/inspect_oauth.py", "w") as f:
f.write(script)
sftp.close()
_, o, e = c.exec_command("cd /opt/douyinWEB/backend && .venv/bin/python /tmp/inspect_oauth.py", timeout=120)
print(o.read().decode("utf-8", "replace"))
print(e.read().decode("utf-8", "replace"))
c.close()