89 lines
2.6 KiB
Python
89 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Wipe rooms on fresh dy.nomadro.live install (no default Douyin rooms)."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
|
|
def main() -> int:
|
|
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,
|
|
banner_timeout=120,
|
|
)
|
|
cmd = r"""
|
|
cd /opt/douyinWEB/backend
|
|
./.venv/bin/python - <<'PY'
|
|
import sqlite3
|
|
from pathlib import Path
|
|
from app import db
|
|
|
|
rooms = db.list_rooms()
|
|
print("before", len(rooms))
|
|
for r in rooms:
|
|
print("-", r if isinstance(r, str) else (r.get("id"), (r.get("url") or r.get("name") or "")[:80]))
|
|
|
|
p = Path("data/monitor.db")
|
|
con = sqlite3.connect(str(p))
|
|
tables = [r[0] for r in con.execute("SELECT name FROM sqlite_master WHERE type='table'").fetchall()]
|
|
print("tables", [t for t in tables if "room" in t.lower() or t in {"settings","kv"}][:40])
|
|
# dump schema-ish
|
|
for t in tables:
|
|
if "room" in t.lower():
|
|
cols = [x[1] for x in con.execute(f"PRAGMA table_info({t})").fetchall()]
|
|
n = con.execute(f"SELECT COUNT(*) FROM {t}").fetchone()[0]
|
|
print("tbl", t, "cols", cols[:12], "n", n)
|
|
rows = con.execute(f"SELECT * FROM {t} LIMIT 5").fetchall()
|
|
print("sample", rows)
|
|
|
|
# Prefer API helpers if present
|
|
deleted = 0
|
|
if hasattr(db, "delete_room"):
|
|
for r in list(db.list_rooms()):
|
|
rid = r if isinstance(r, str) else str((r or {}).get("id") or "")
|
|
if rid:
|
|
db.delete_room(rid)
|
|
deleted += 1
|
|
print("deleted_via_api", deleted)
|
|
elif "rooms" in tables:
|
|
con.execute("DELETE FROM rooms")
|
|
con.commit()
|
|
print("deleted_sql_rooms")
|
|
else:
|
|
# fallback: wipe entire monitor.db and let app recreate empty
|
|
con.close()
|
|
for f in ("data/monitor.db", "data/monitor.db-shm", "data/monitor.db-wal"):
|
|
Path(f).unlink(missing_ok=True)
|
|
print("wiped_monitor_db_files")
|
|
# reopen app db
|
|
rooms2 = db.list_rooms()
|
|
print("after_recreate", len(rooms2))
|
|
raise SystemExit(0 if len(rooms2) == 0 else 2)
|
|
|
|
con.close()
|
|
rooms2 = db.list_rooms()
|
|
print("after", len(rooms2))
|
|
print("OK_EMPTY_ROOMS" if len(rooms2) == 0 else "STILL_HAS_ROOMS")
|
|
PY
|
|
"""
|
|
_i, o, e = c.exec_command(cmd, timeout=60)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"))
|
|
code = o.channel.recv_exit_status()
|
|
c.close()
|
|
return code
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|