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

75 lines
2.8 KiB
Python

# -*- coding: utf-8 -*-
import asyncio
import sys
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
REMOTE = r"""
cd /opt/douyinWEB/backend
.venv/bin/python - <<'PY'
import asyncio
import json
from app import db, shorts_oauth, youtube_manage
from app.shorts_upload import refresh_access_token
async def probe(pk):
ch = db.get_shorts_channel(pk)
print('===', pk[:8], ch.get('name'), 'profile', ch.get('oauth_profile_id'), 'yt_id', ch.get('youtube_channel_id') or '(empty)')
creds = shorts_oauth.channel_oauth_creds(ch)
print('client', creds['client_id'][:20]+'...', 'has_refresh', bool(creds['refresh_token']))
try:
token = await refresh_access_token(
client_id=creds['client_id'],
client_secret=creds['client_secret'],
refresh_token=creds['refresh_token'],
)
print('token ok', len(token))
except Exception as e:
print('token FAIL', e)
return
import httpx
async with httpx.AsyncClient(timeout=30, trust_env=False) as client:
for params in (
{'part': 'snippet,statistics', 'mine': 'true'},
{'part': 'snippet,statistics', 'managedByMe': 'true'},
):
r = await client.get('https://www.googleapis.com/youtube/v3/channels', params=params, headers={'Authorization': f'Bearer {token}'})
data = r.json() if r.content else {}
items = data.get('items') or []
err = (data.get('error') or {}).get('message')
print('params', params, 'status', r.status_code, 'items', len(items), 'err', err)
for it in items[:5]:
sn = it.get('snippet') or {}
st = it.get('statistics') or {}
print(' ', it.get('id'), sn.get('title'), sn.get('customUrl'), 'videos', st.get('videoCount'))
try:
prof = await youtube_manage.fetch_channel_profile(pk)
print('fetch_profile OK', prof.get('title'), prof.get('youtube_channel_id'))
except Exception as e:
print('fetch_profile FAIL', e)
async def main():
rows = [c for c in db.list_shorts_channels() if str(c.get('oauth_profile_id') or '').upper() == 'B']
print('B channels', len(rows))
for ch in rows:
await probe(ch['id'])
# compare profile A working channel
a = [c for c in db.list_shorts_channels() if str(c.get('oauth_profile_id') or '').upper() == 'A' and c.get('youtube_channel_id')][:1]
if a:
print('--- compare A ---')
await probe(a[0]['id'])
asyncio.run(main())
PY
"""
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)
_i, o, e = c.exec_command(REMOTE, timeout=120)
print(o.read().decode("utf-8", "replace"))
print(e.read().decode("utf-8", "replace")[:1500])
c.close()