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>
93 lines
3.3 KiB
Python
93 lines
3.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
import sys
|
|
import time
|
|
from collections import defaultdict
|
|
from datetime import datetime, timezone, timedelta
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
from app import db
|
|
|
|
BJ = timezone(timedelta(hours=8))
|
|
db.init_db()
|
|
cutoff = time.time() - 86400 * 2
|
|
|
|
with db._lock:
|
|
conn = db._connect()
|
|
try:
|
|
rows = conn.execute(
|
|
"""
|
|
SELECT id, room_id, anchor_name, channel_pk, status, clip_path,
|
|
youtube_video_id, youtube_url, push_date, created_at, finished_at,
|
|
upload_at, attempts, updated_at, started_at
|
|
FROM shorts_jobs
|
|
WHERE (finished_at > ? OR updated_at > ?)
|
|
AND (youtube_video_id != '' OR status IN ('uploaded','uploading','scheduled'))
|
|
ORDER BY updated_at DESC
|
|
LIMIT 100
|
|
""",
|
|
(cutoff, cutoff),
|
|
).fetchall()
|
|
print("recent_rows", len(rows))
|
|
high_attempts = []
|
|
for r in rows:
|
|
d = dict(r)
|
|
if int(d.get("attempts") or 0) >= 2 and d.get("youtube_video_id"):
|
|
high_attempts.append(d)
|
|
if d.get("youtube_video_id"):
|
|
fin = float(d.get("finished_at") or 0)
|
|
st = float(d.get("started_at") or 0)
|
|
ts = datetime.fromtimestamp(fin, BJ).strftime("%m-%d %H:%M:%S") if fin else "-"
|
|
dur = int(fin - st) if fin and st else -1
|
|
print(
|
|
f"UP att={d['attempts']} dur={dur}s {d['id'][:8]} room={d['room_id']} "
|
|
f"anchor={d['anchor_name']!r} yt={d['youtube_video_id']} day={d['push_date']} fin={ts}"
|
|
)
|
|
|
|
print("\n--- uploaded with attempts>=2 (likely reclaim re-upload) ---")
|
|
for d in high_attempts[:30]:
|
|
print(
|
|
f"att={d['attempts']} {d['id']} room={d['room_id']} "
|
|
f"yt={d['youtube_video_id']} started={d['started_at']} finished={d['finished_at']}"
|
|
)
|
|
|
|
print("\n--- duplicate room+day with multiple youtube ids ---")
|
|
multi = conn.execute(
|
|
"""
|
|
SELECT room_id, push_date, COUNT(*) AS c,
|
|
GROUP_CONCAT(youtube_video_id) AS yts,
|
|
GROUP_CONCAT(substr(id,1,8)) AS ids,
|
|
GROUP_CONCAT(CAST(attempts AS TEXT)) AS atts
|
|
FROM shorts_jobs
|
|
WHERE youtube_video_id != ''
|
|
AND push_date >= date('now', '-3 day')
|
|
GROUP BY room_id, push_date
|
|
HAVING c > 1
|
|
ORDER BY c DESC
|
|
LIMIT 20
|
|
"""
|
|
).fetchall()
|
|
for r in multi:
|
|
print(dict(r))
|
|
|
|
print("\n--- same room multiple jobs today ---")
|
|
multi2 = conn.execute(
|
|
"""
|
|
SELECT room_id, push_date, COUNT(*) AS c,
|
|
GROUP_CONCAT(status) AS statuses,
|
|
GROUP_CONCAT(substr(id,1,8)) AS ids,
|
|
GROUP_CONCAT(youtube_video_id) AS yts
|
|
FROM shorts_jobs
|
|
WHERE push_date >= date('now', '-1 day')
|
|
AND room_id != ''
|
|
AND status NOT IN ('failed','skipped')
|
|
GROUP BY room_id, push_date
|
|
HAVING c > 1
|
|
ORDER BY c DESC
|
|
LIMIT 30
|
|
"""
|
|
).fetchall()
|
|
for r in multi2:
|
|
print(dict(r))
|
|
finally:
|
|
conn.close()
|