diff --git a/hik_uptime/main.py b/hik_uptime/main.py index 817f3af..3949645 100644 --- a/hik_uptime/main.py +++ b/hik_uptime/main.py @@ -1,5 +1,5 @@ -import asyncio import time +from datetime import datetime, timedelta, timezone from pathlib import Path import pyautogui @@ -12,7 +12,7 @@ from hik_uptime.custom_exception import NoWindowException def read_config(): home_dir = Path.home() with open( - home_dir / ".config" / "hik-uptime" / "config.yaml", "r", encoding="utf-8" + home_dir / ".config" / "hik-uptime" / "config.yaml", "r", encoding="utf-8" ) as f: config = yaml.safe_load(f) return config @@ -64,12 +64,21 @@ def get_status(): if color_50_hex != "#0db318": offline_devices.append("报警主机50") - print(offline_devices) + if len(offline_devices) > 0: + print(offline_devices) + else: + print("No offline devices") + + current_time = datetime.now() + tz = timezone(timedelta(hours=8)) + happen_time = current_time.astimezone(tz).strftime('%Y-%m-%dT%H:%M:%S.%f%z') for offline_device in offline_devices: push_json = { "eventType": "报警主机离线", + "happenTime": happen_time, "deviceName": offline_device, + "regionName": offline_device, "eventLvl": 2, "data": {"typeName": f"{offline_device}离线"}, "userIds": ["2110"], @@ -79,6 +88,7 @@ def get_status(): json=push_json, ) print(resp.content.decode("utf-8")) + time.sleep(1) def capture_loop(): @@ -91,7 +101,7 @@ def capture_loop(): def run_app(): - asyncio.run(capture_loop()) + capture_loop() if __name__ == "__main__": diff --git a/pyproject.toml b/pyproject.toml index 52ec1f9..8566216 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "hik-uptime" -version = "0.1.2" +version = "0.1.3" description = "" authors = ["quantulr <35954003+quantulr@users.noreply.github.com>"] readme = "README.md"