python工程,kafka消息对接转换成配置文件并完成类似看门狗监控linux系统进程,定期清理日志
wangrong
2025-04-04 9fa450e81ee48a012abbff44ce4094ecf19265ff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import json
 
def format_regions(regions):
    """格式化坐标数组为字符串"""
    return ",".join(f"({x},{y})" for x, y in regions)
 
def parse_camera_list(file_path):
    with open(file_path, 'r', encoding='utf-8') as file:
        data = json.load(file)
 
    output_lines = []
 
    for channel in data.get("channels", []):
        channel_id = channel.get("id")
        url = channel.get("url")
 
        for action in channel.get("actions", []):
            action_type = action.get("action")
 
            if action_type == "JAM":
                regions = action.get("regions", [])
                formatted_regions = format_regions(regions)
                line = f"{url} 0.5 172.18.0.247:9092 3 {channel_id} true {formatted_regions}"
                output_lines.append(line)
 
    return output_lines
 
if __name__ == "__main__":
    # 替换为你的文件路径
    file_path = "camera.list.txt"
 
    # 解析并输出结果
    result = parse_camera_list(file_path)
    for line in result:
        print(line)