douyinWEB/scripts/_verify_all_oauth.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

43 lines
1.6 KiB
Python

# -*- coding: utf-8 -*-
import paramiko
script = """import sys
sys.path.insert(0, '/opt/douyinWEB/backend')
from app import db
from app import youtube_manage as ytm
from app.yt_channel_meta import oauth_meta_from_channel
enabled = db.list_shorts_channels(enabled=True)
all_ok = True
print('=== enabled channels', len(enabled), '===')
for ch in sorted(enabled, key=lambda x: str(x.get('name') or '')):
sn = ytm._snippet_from_channel_row(ch) or {}
meta = oauth_meta_from_channel(ch)
ok = int(ch.get('oauth_ok') or 0) == 1 and 'force-ssl' not in str(ch.get('oauth_error') or '')
if not ok:
all_ok = False
mark = 'OK' if ok else 'BAD'
print(f"{mark} | {ch.get('name')} | profile {ch.get('oauth_profile_id') or '-'} | {sn.get('custom_url') or ch.get('youtube_channel_id')} | {ch.get('oauth_error') or ''}")
bad = [c for c in enabled if int(c.get('oauth_ok') or 0) != 1 or 'force-ssl' in str(c.get('oauth_error') or '')]
print('=== summary ===')
print('enabled', len(enabled))
print('oauth_ok', len(enabled) - len(bad))
print('oauth_bad', len(bad))
print('all_ok', all_ok)
"""
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)
sftp = c.open_sftp()
with sftp.file("/tmp/oauth_check.py", "w") as f:
f.write(script)
sftp.close()
_, o, e = c.exec_command("cd /opt/douyinWEB/backend && .venv/bin/python /tmp/oauth_check.py", timeout=120)
print(o.read().decode("utf-8", "replace"))
err = e.read().decode("utf-8", "replace").strip()
if err:
print("ERR", err[:300])
c.close()