diff --git a/hik_uptime/__pycache__/__init__.cpython-311.pyc b/hik_uptime/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..cab54ac Binary files /dev/null and b/hik_uptime/__pycache__/__init__.cpython-311.pyc differ diff --git a/hik_uptime/__pycache__/custom_exception.cpython-311.pyc b/hik_uptime/__pycache__/custom_exception.cpython-311.pyc new file mode 100644 index 0000000..909713a Binary files /dev/null and b/hik_uptime/__pycache__/custom_exception.cpython-311.pyc differ diff --git a/hik_uptime/custom_exception.py b/hik_uptime/custom_exception.py new file mode 100644 index 0000000..cbc0d79 --- /dev/null +++ b/hik_uptime/custom_exception.py @@ -0,0 +1,2 @@ +class NoWindowException(Exception): + pass diff --git a/hik_uptime/main.py b/hik_uptime/main.py index beaa760..cd0e1b1 100644 --- a/hik_uptime/main.py +++ b/hik_uptime/main.py @@ -1,27 +1,41 @@ +import time +from pathlib import Path + import pyautogui import pytesseract +import yaml + +from hik_uptime.custom_exception import NoWindowException -# # ws = pygetwindow.getAllWindows() -# # for x in ws: -# # print(x.title) -# -# wd = pygetwindow.getWindowsWithTitle("PowerShell") -# print(wd[0]) -# wd[0].activate() -# wd[0].maximize() -# screenshot = pyautogui.screenshot("screenshot.png") -# print(screenshot) -# print(pytesseract.get_languages()) -# result = pytesseract.image_to_string(screenshot) -# # print(result) +def read_config(): + home_dir = Path.home() + with open(home_dir / ".config" / "hik-uptime" / "config.yaml", "r", encoding="utf-8") as f: + config = yaml.safe_load(f) + return config + def get_status(): - window = pyautogui.getWindowsWithTitle("Mozilla Firefox") - + # 找到窗口并最大化 + window = pyautogui.getWindowsWithTitle("设置") + if len(window) == 0: + raise NoWindowException("No window found") + print(window[0]) window = window[0] window.maximize() window.activate() + + config = read_config() + # TODO: 切换到烟感设备列表 + for pos in config['menus']: + time.sleep(1.5) + pyautogui.click(pos['x'], pos['y']) + + # TODO: OCR 获取已离线的设备名称数量 + color = pyautogui.pixel(138, 8) + print('#{:02x}{:02x}{:02x}'.format(*color)) + + # TODO: 向 /eventRcv 发送模拟订阅报文 # pyautogui.click(900, 140) # clipboard.copy("网络") # pyautogui.hotkey('ctrl', 'a') @@ -29,7 +43,7 @@ def get_status(): # pyautogui.press('enter') # pyautogui.click(x=window.width // 2, y=window.height // 2) screenshot = pyautogui.screenshot() - screenshot = screenshot.crop((313, 46, 1118, 79)) + screenshot = screenshot.crop((464, 412, 1401, 934)) screenshot.save('screenshot.png') result = pytesseract.image_to_string(screenshot) print(result) diff --git a/hik_uptime/screenshot.png b/hik_uptime/screenshot.png index 8d702d5..78b97e7 100644 Binary files a/hik_uptime/screenshot.png and b/hik_uptime/screenshot.png differ