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

84 lines
2.6 KiB
Python

# -*- coding: utf-8 -*-
"""Reassign orphaned shorts jobs from deleted asian streetfood card to keeper."""
from __future__ import annotations
import sys
import time
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
PASS = "4669805"
KEEP = "82102486-f5d7-434c-b508-4c6a10c5f325"
DROP = "51d51d27-8f7c-4a92-b1d5-5fd55e844c4e"
REMOTE = f'''
import sqlite3, json
p="/opt/douyinWEB/backend/data/monitor.db"
con=sqlite3.connect(p)
con.row_factory=sqlite3.Row
keep="{KEEP}"
drop="{DROP}"
print("keeper exists", con.execute("SELECT id,name FROM shorts_channels WHERE id=?",(keep,)).fetchone())
print("drop exists", con.execute("SELECT id FROM shorts_channels WHERE id=?",(drop,)).fetchone())
before=list(con.execute(
"SELECT id,status,channel_pk FROM shorts_jobs WHERE channel_pk=?", (drop,)))
print("jobs_on_drop", [dict(r) for r in before])
con.execute("UPDATE shorts_jobs SET channel_pk=? WHERE channel_pk=?", (keep, drop))
# also yt_long if any pointed at drop
try:
n=con.execute("UPDATE yt_long_channels SET source_shorts_channel_pk=? WHERE source_shorts_channel_pk=?", (keep, drop)).rowcount
print("yt_long_source_rewritten", n)
except Exception as e:
print("yt_long skip", e)
con.commit()
after=list(con.execute(
"SELECT status, COUNT(*) n FROM shorts_jobs WHERE channel_pk=? GROUP BY status", (keep,)))
print("jobs_on_keep", [dict(r) for r in after])
# confirm no remaining dups
dups=list(con.execute("""
SELECT youtube_channel_id, COUNT(*) n FROM shorts_channels
WHERE youtube_channel_id='UCjQ8jnBm2N4FGRowNXcXThw' GROUP BY youtube_channel_id
"""))
print("dup_check", [dict(r) for r in dups])
print("DONE")
'''
def main():
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
for i in range(8):
try:
c.connect(
"107.173.30.245",
4014,
"eric",
PASS,
timeout=60,
banner_timeout=120,
allow_agent=False,
look_for_keys=False,
)
break
except Exception as ex:
print("ssh", i, type(ex).__name__, flush=True)
time.sleep(2 + i)
else:
raise SystemExit("ssh failed")
sftp = c.open_sftp()
with sftp.file("/tmp/_migrate_jobs_physical.py", "w") as f:
f.write(REMOTE)
sftp.close()
_, o, e = c.exec_command(
f"echo '{PASS}' | sudo -S -p '' python3 /tmp/_migrate_jobs_physical.py",
timeout=60,
)
print((o.read() + e.read()).decode("utf-8", "replace"), flush=True)
c.close()
if __name__ == "__main__":
main()