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 import time
from datetime import datetime, timedelta, timezone
from pathlib import Path from pathlib import Path
import pyautogui import pyautogui
@ -12,7 +12,7 @@ from hik_uptime.custom_exception import NoWindowException
def read_config(): def read_config():
home_dir = Path.home() home_dir = Path.home()
with open( 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: ) as f:
config = yaml.safe_load(f) config = yaml.safe_load(f)
return config return config
@ -64,12 +64,21 @@ def get_status():
if color_50_hex != "#0db318": if color_50_hex != "#0db318":
offline_devices.append("报警主机50") 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: for offline_device in offline_devices:
push_json = { push_json = {
"eventType": "报警主机离线", "eventType": "报警主机离线",
"happenTime": happen_time,
"deviceName": offline_device, "deviceName": offline_device,
"regionName": offline_device,
"eventLvl": 2, "eventLvl": 2,
"data": {"typeName": f"{offline_device}离线"}, "data": {"typeName": f"{offline_device}离线"},
"userIds": ["2110"], "userIds": ["2110"],
@ -79,6 +88,7 @@ def get_status():
json=push_json, json=push_json,
) )
print(resp.content.decode("utf-8")) print(resp.content.decode("utf-8"))
time.sleep(1)
def capture_loop(): def capture_loop():
@ -91,7 +101,7 @@ def capture_loop():
def run_app(): def run_app():
asyncio.run(capture_loop()) capture_loop()
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "hik-uptime" name = "hik-uptime"
version = "0.1.2" version = "0.1.3"
description = "" description = ""
authors = ["quantulr <35954003+quantulr@users.noreply.github.com>"] authors = ["quantulr <35954003+quantulr@users.noreply.github.com>"]
readme = "README.md" readme = "README.md"