diff --git a/hik_push/__pycache__/main.cpython-312.pyc b/hik_push/__pycache__/main.cpython-312.pyc index 3e339fe..7c7c55b 100644 Binary files a/hik_push/__pycache__/main.cpython-312.pyc and b/hik_push/__pycache__/main.cpython-312.pyc differ diff --git a/hik_push/mapping/__pycache__/user_map.cpython-312.pyc b/hik_push/mapping/__pycache__/user_map.cpython-312.pyc new file mode 100644 index 0000000..734a98b Binary files /dev/null and b/hik_push/mapping/__pycache__/user_map.cpython-312.pyc differ diff --git a/hik_push/read_event.py b/hik_push/read_event.py index 8194fda..d9c7ab7 100644 --- a/hik_push/read_event.py +++ b/hik_push/read_event.py @@ -88,18 +88,26 @@ async def read_event(): event_type = event['eventType'] event_type_str = mapping.get(event_type, "未知事件类型") event['eventType'] = event_type_str - # ip address - ip_address = event["data"]["ipAddress"] - # 根据 ip_address 获取对应设备名称 - device_name = device_map.get(ip_address, "未知设备") - event['deviceName'] = device_name - # print(event['data'][event['data']['eventType']]) - # TODO: 根据 ip_address 获取对应 userid - user_ids = user_map.get(ip_address, []) - event['userIds'] = user_ids + if "data" in event: + # 如果存在 data 属性 + # ip_address + ip_address = event["data"]["ipAddress"] + + # 根据 ip_address 获取对应设备名称 + device_name = device_map.get(ip_address, "未知设备") + event['data']['deviceName'] = device_name + + # 根据 ip_address 获取对应 userid 数组 + user_ids = user_map.get(ip_address, []) + event['data']['userIds'] = user_ids + # 替换分析结果字段 + if "eventType" in event['data']: + detection_field_name = event['data']['eventType'] + if detection_field_name in event['data']: + event['data']["_detectionResult"] = event['data'].pop(detection_field_name) # TODO: 请求推送 api # - print(event, device_name) + print(event) except Exception as e: print("error: ", e)