Files
quantulr 0b77166eed update
2024-04-08 17:25:13 +08:00

55 lines
1.4 KiB
Python

import time
from pathlib import Path
import pyautogui
import pytesseract
import yaml
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") as f:
config = yaml.safe_load(f)
return config
def get_status():
# 找到窗口并最大化
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')
# pyautogui.hotkey('ctrl', 'v')
# pyautogui.press('enter')
# pyautogui.click(x=window.width // 2, y=window.height // 2)
screenshot = pyautogui.screenshot()
screenshot = screenshot.crop((464, 412, 1401, 934))
screenshot.save('screenshot.png')
result = pytesseract.image_to_string(screenshot)
print(result)
# pyautogui.click(1920, 20)
if __name__ == "__main__":
get_status()