# -*- coding: utf-8 -*- """Fix oauth_profile_id on dy for channels whose client_id matches merged profiles.""" from __future__ import annotations import json import sys import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") FIX = r""" import json, sqlite3, time conn=sqlite3.connect('/opt/douyinWEB/backend/data/monitor.db') conn.row_factory=sqlite3.Row raw=conn.execute("SELECT value FROM kv_settings WHERE key='shorts_oauth_profiles'").fetchone() profiles=json.loads(raw[0] if raw else '[]') print('PROFILES', [{k:p.get(k) for k in ('id','label','client_id')} for p in profiles]) cid_to_pid={str(p.get('client_id') or ''): str(p.get('id') or '') for p in profiles} now=time.time() fixed_sc=0 for r in conn.execute('SELECT id,name,client_id,oauth_profile_id,youtube_channel_id FROM shorts_channels').fetchall(): want=cid_to_pid.get(str(r['client_id'] or '').strip(), '') cur=str(r['oauth_profile_id'] or '') if want and want != cur: conn.execute('UPDATE shorts_channels SET oauth_profile_id=?, updated_at=? WHERE id=?', (want, now, r['id'])) print('FIX_SC', r['name'], cur, '->', want, r['youtube_channel_id']) fixed_sc += 1 fixed_yl=0 for r in conn.execute('SELECT id,name,client_id,oauth_profile_id,youtube_channel_id FROM yt_long_channels').fetchall(): want=cid_to_pid.get(str(r['client_id'] or '').strip(), '') cur=str(r['oauth_profile_id'] or '') if want and want != cur: conn.execute('UPDATE yt_long_channels SET oauth_profile_id=?, updated_at=? WHERE id=?', (want, now, r['id'])) print('FIX_YL', r['name'], cur, '->', want, r['youtube_channel_id']) fixed_yl += 1 conn.commit() print('fixed_sc', fixed_sc, 'fixed_yl', fixed_yl) print('rooms', conn.execute('SELECT count(*) FROM rooms').fetchone()[0]) print('shorts', conn.execute('SELECT count(*) FROM shorts_channels').fetchone()[0]) print('yt_long', conn.execute('SELECT count(*) FROM yt_long_channels').fetchone()[0]) # keyed assign for r in conn.execute("SELECT name, youtube_channel_id, length(stream_key) sk FROM yt_assign_groups WHERE length(stream_key)>0").fetchall(): print('KEYED', dict(r)) redir=conn.execute("SELECT value FROM kv_settings WHERE key='shorts_oauth_redirect_uri'").fetchone() print('redirect', redir[0] if redir else None) conn.close() """ 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/_fix_profiles.py", "w") as f: f.write(FIX) sftp.close() _, o, e = c.exec_command("cd /opt/douyinWEB/backend && .venv/bin/python /tmp/_fix_profiles.py 2>&1", timeout=60) print(o.read().decode("utf-8", "replace")) print(e.read().decode("utf-8", "replace")) c.close()