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

55 lines
2.1 KiB
Python

# -*- coding: utf-8 -*-
"""Diagnose Profile C 大师兄2016 OAuth start URL."""
from __future__ import annotations
import sys
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
SCRIPT = r"""
from urllib.parse import urlparse, parse_qs, unquote
from app import db, shorts_oauth
db.init_db()
chs = [c for c in db.list_shorts_channels(enabled=None)
if '大师兄2016' in str(c.get('name') or '')]
for ch in chs:
print('---')
print('name', ch.get('name'))
print('id', ch.get('id'))
print('ycid', ch.get('youtube_channel_id'))
print('profile', ch.get('oauth_profile_id'))
print('oauth_ok', ch.get('oauth_ok'), 'err', (ch.get('oauth_error') or '')[:120])
print('rt_len', len(str(ch.get('refresh_token') or '')))
client = shorts_oauth.resolve_oauth_client(ch)
print('client_source', client.get('source'), 'pid', client.get('profile_id'))
print('client_id', (client.get('client_id') or '')[:48])
url = shorts_oauth.build_authorize_url(channel_pk=ch['id'], request_base='https://dy.nomadro.live')
q = parse_qs(urlparse(url).query)
print('redirect_uri', q.get('redirect_uri'))
print('scope', unquote(q.get('scope', [''])[0])[:200])
print('prompt', q.get('prompt'))
cfg = db.get_settings_map()
print('cfg_redirect', cfg.get('shorts_oauth_redirect_uri'))
print('resolved', shorts_oauth.resolve_redirect_uri('https://dy.nomadro.live'))
for p in shorts_oauth.list_oauth_profiles(public=True):
print('PROF', p.get('id'), 'cfg', p.get('configured'), 'email', p.get('email') or '', 'cid', (p.get('client_id') or '')[:36])
"""
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect("108.174.50.68", 22, "root", "Xiao4669805", timeout=45, allow_agent=False, look_for_keys=False)
sftp = c.open_sftp()
with sftp.file("/tmp/_diag_oauth_c.py", "w") as f:
f.write(SCRIPT)
sftp.close()
_, o, e = c.exec_command(
"cd /opt/douyinWEB/backend && PYTHONPATH=. .venv/bin/python /tmp/_diag_oauth_c.py 2>&1",
timeout=60,
)
print(o.read().decode("utf-8", "replace"))
print(e.read().decode("utf-8", "replace"))
c.close()