From a1dbd6c55ba3a6765c8576735f906766b6ce7f81 Mon Sep 17 00:00:00 2001 From: 16337 <1633794139@qq.com> Date: Sat, 14 Feb 2026 11:36:07 +0800 Subject: [PATCH] =?UTF-8?q?tools(recovery):=20=E6=B7=BB=E5=8A=A0=E6=91=84?= =?UTF-8?q?=E5=83=8F=E5=A4=B4=E9=85=8D=E7=BD=AE=E6=81=A2=E5=A4=8D=E5=B7=A5?= =?UTF-8?q?=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 用于恢复因config-sync bug丢失的摄像头配置 - 交互式输入RTSP URL - 直接写入数据库 - 适用于云端配置也丢失的情况 Co-Authored-By: Claude Opus 4.6 --- restore_cameras.py | 72 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 restore_cameras.py diff --git a/restore_cameras.py b/restore_cameras.py new file mode 100644 index 0000000..8b9857d --- /dev/null +++ b/restore_cameras.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python3 +""" +摄像头配置恢复助手 +如果云端配置丢失,使用此脚本手动添加摄像头配置 +""" +import sys +from pathlib import Path +sys.path.insert(0, str(Path(__file__).parent)) + +from config.database import get_sqlite_manager + +def main(): + print("=== Camera Config Recovery Tool ===\n") + print("This tool helps you restore the 3 missing camera configs") + print("You need to provide the RTSP URLs for:") + print(" 1. cam_1f0e3dad9990") + print(" 2. cam_6f4922f45568") + print(" 3. cam_c51ce410c124") + print() + + cameras_to_add = [] + + for i, cam_id in enumerate(['cam_1f0e3dad9990', 'cam_6f4922f45568', 'cam_c51ce410c124'], 1): + print(f"\nCamera {i}: {cam_id}") + rtsp_url = input(f" RTSP URL (or press Enter to skip): ").strip() + + if not rtsp_url: + print(f" Skipped") + continue + + name = input(f" Display Name (default: {cam_id}): ").strip() or cam_id + + cameras_to_add.append({ + "camera_id": cam_id, + "rtsp_url": rtsp_url, + "name": name + }) + + if not cameras_to_add: + print("\n[CANCELLED] No cameras to add") + return + + print("\n" + "=" * 50) + print("Summary:") + for cam in cameras_to_add: + print(f" - {cam['camera_id']}: {cam['name']}") + print(f" RTSP: {cam['rtsp_url'][:50]}...") + print("=" * 50) + + response = input("\nAdd these cameras to database? (yes/no): ").strip().lower() + + if response != 'yes': + print("\n[CANCELLED]") + return + + # Add cameras to database + db_manager = get_sqlite_manager() + + for cam in cameras_to_add: + try: + db_manager.save_camera_config(cam) + print(f" [OK] Added: {cam['camera_id']}") + except Exception as e: + print(f" [FAIL] Failed to add {cam['camera_id']}: {e}") + + print("\n[SUCCESS] Cameras added to database") + print("\nNext steps:") + print(" 1. Restart the Edge service") + print(" 2. The 3 cameras should now start streaming") + +if __name__ == "__main__": + main()