刷新url暂时测试通过
This commit is contained in:
58
test_cam.py
58
test_cam.py
@@ -26,28 +26,40 @@ def get_camera_preview_url(camera_index_code):
|
||||
response = requests.request(method, url, headers=headers, data=body, verify=False)
|
||||
return response.json()
|
||||
|
||||
# 读取 config.yaml
|
||||
with open('config.yaml', 'r', encoding='utf-8') as f:
|
||||
config = yaml.safe_load(f)
|
||||
# # for test
|
||||
# def get_camera_preview_url(camera_index_code):
|
||||
# """测试用的方法,直接返回固定结果"""
|
||||
# return {
|
||||
# "code": "0",
|
||||
# "msg": "SUCCESS",
|
||||
# "data": {
|
||||
# "url": "rtsp://localhost:8554/test"
|
||||
# }
|
||||
# }
|
||||
|
||||
# 遍历所有摄像头
|
||||
for camera in config['cameras']:
|
||||
if 'index' in camera:
|
||||
index = camera['index']
|
||||
print(f"正在获取摄像头 {camera['name']} (index: {index}) 的预览地址...")
|
||||
result = get_camera_preview_url(index)
|
||||
print(f"API返回结果: {result}")
|
||||
|
||||
# 提取 url 并更新到 config
|
||||
if 'data' in result and 'url' in result['data']:
|
||||
rtsp_url = result['data']['url']
|
||||
camera['rtsp_url'] = rtsp_url
|
||||
print(f"更新 rtsp_url: {rtsp_url}")
|
||||
else:
|
||||
print(f"未找到 url 在返回结果中")
|
||||
|
||||
# 保存更新后的 config.yaml
|
||||
with open('config.yaml', 'w', encoding='utf-8') as f:
|
||||
yaml.dump(config, f, default_flow_style=False, allow_unicode=True)
|
||||
|
||||
print("config.yaml 已更新")
|
||||
# # 读取 config.yaml
|
||||
# with open('config.yaml', 'r', encoding='utf-8') as f:
|
||||
# config = yaml.safe_load(f)
|
||||
#
|
||||
# # 遍历所有摄像头
|
||||
# for camera in config['cameras']:
|
||||
# if 'index' in camera:
|
||||
# index = camera['index']
|
||||
# print(f"正在获取摄像头 {camera['name']} (index: {index}) 的预览地址...")
|
||||
# result = get_camera_preview_url(index)
|
||||
# print(f"API返回结果: {result}")
|
||||
#
|
||||
# # 提取 url 并更新到 config
|
||||
# if 'data' in result and 'url' in result['data']:
|
||||
# rtsp_url = result['data']['url']
|
||||
# camera['rtsp_url'] = rtsp_url
|
||||
# print(f"更新 rtsp_url: {rtsp_url}")
|
||||
# else:
|
||||
# print(f"未找到 url 在返回结果中")
|
||||
#
|
||||
# # 保存更新后的 config.yaml
|
||||
# with open('config.yaml', 'w', encoding='utf-8') as f:
|
||||
# yaml.dump(config, f, default_flow_style=False, allow_unicode=True)
|
||||
#
|
||||
# print("config.yaml 已更新")
|
||||
|
||||
Reference in New Issue
Block a user