This commit is contained in:
quantulr
2024-04-10 09:51:37 +08:00
parent a777e6be6b
commit b2d2a2d38d
2 changed files with 15 additions and 5 deletions

View File

@ -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__":