sh2/d2ypp2/tools/query_host03_youtube_events.py
eric 278b48497e Add YouTube relay log tooling and optional hub service controls.
This captures the current live stack updates across the API, Linux service scripts, tests, diagnostics, and exported console assets so the Ubuntu deployment can pull a consistent test3 build.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-30 05:10:09 -05:00

107 lines
3.8 KiB
Python

#!/usr/bin/env python3
"""Query youtube_live_events on 10.88.0.3 for lane1 ~12h ago session."""
from __future__ import annotations
import json
import time
import paramiko
HOST, USER, PASS = "10.88.0.3", "eric", "Xiao4669805"
REMOTE_PY = r'''
import sqlite3, json, time, os
from datetime import datetime
paths = [
"/opt/live/d2ypp/config/hub_state.sqlite",
"/home/eric/d2ypp2-src/config/hub_state.sqlite",
]
now = time.time()
print("now", now, datetime.fromtimestamp(now).isoformat())
print("12h_ago", now - 12*3600, datetime.fromtimestamp(now - 12*3600).isoformat())
for p in paths:
if not os.path.exists(p):
print("missing", p)
continue
print("\nDB", p, "size", os.path.getsize(p))
conn = sqlite3.connect(p)
conn.row_factory = sqlite3.Row
tables = [r[0] for r in conn.execute("SELECT name FROM sqlite_master WHERE type='table'").fetchall()]
print("tables", tables)
if "youtube_live_events" not in tables:
conn.close()
continue
cnt = conn.execute("SELECT COUNT(*) FROM youtube_live_events").fetchone()[0]
print("event_count", cnt)
rows = conn.execute(
"""SELECT id, process, channel_name, source_url, source_room_id, source_title,
status, started_at, ended_at, duration_seconds, last_seen_at
FROM youtube_live_events
ORDER BY started_at DESC LIMIT 30"""
).fetchall()
for r in rows:
d = dict(r)
for k in ("started_at", "ended_at", "last_seen_at"):
if d.get(k):
d[k + "_iso"] = datetime.fromtimestamp(float(d[k])).isoformat()
print(json.dumps(d, ensure_ascii=False))
# events around 12h ago with duration ~125 min (7500s)
target = now - 12*3600
rows2 = conn.execute(
"""SELECT id, process, channel_name, source_url, source_room_id, source_title,
status, started_at, ended_at, duration_seconds
FROM youtube_live_events
WHERE started_at BETWEEN ? AND ?
OR (ended_at BETWEEN ? AND ?)
OR (started_at < ? AND (ended_at IS NULL OR ended_at > ?))
ORDER BY started_at DESC""",
(target - 4*3600, target + 4*3600, target - 4*3600, target + 4*3600, target, target),
).fetchall()
print("\n--- events near 12h ago ---")
for r in rows2:
d = dict(r)
for k in ("started_at", "ended_at"):
if d.get(k):
d[k + "_iso"] = datetime.fromtimestamp(float(d[k])).isoformat()
print(json.dumps(d, ensure_ascii=False))
rows3 = conn.execute(
"""SELECT id, process, source_url, source_title, duration_seconds, started_at, ended_at
FROM youtube_live_events
WHERE duration_seconds BETWEEN 7000 AND 8000
ORDER BY started_at DESC LIMIT 20"""
).fetchall()
print("\n--- duration 7000-8000s (~2h) ---")
for r in rows3:
d = dict(r)
for k in ("started_at", "ended_at"):
if d.get(k):
d[k + "_iso"] = datetime.fromtimestamp(float(d[k])).isoformat()
print(json.dumps(d, ensure_ascii=False))
if "kv" in tables:
for row in conn.execute("SELECT key FROM kv").fetchall():
print("kv_key", row[0])
r = conn.execute("SELECT value FROM kv WHERE key='youtube_pro_channels_v1'").fetchone()
if r:
print("youtube_pro_channels", r[0][:3000])
conn.close()
'''
def main() -> int:
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(HOST, username=USER, password=PASS, timeout=15)
_, o, e = c.exec_command(f"python3 - <<'PY'\n{REMOTE_PY}\nPY", timeout=90, get_pty=True)
out = (o.read() + e.read()).decode("utf-8", "replace")
c.close()
print(out)
return 0
if __name__ == "__main__":
raise SystemExit(main())