This commit is contained in:
quantulr
2024-04-08 17:25:13 +08:00
parent 2c1cd822fc
commit 0b77166eed
5 changed files with 32 additions and 16 deletions

Binary file not shown.

View File

@ -0,0 +1,2 @@
class NoWindowException(Exception):
pass

View File

@ -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)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB