123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- import hug
- from bottle import route, run
- import pyautogui
- import random
- import time
- import os
- import win32gui, win32con
- import autoit
- import pyperclip
- import pythoncom
- import datetime
- hug.API(__name__).http.output_format = hug.output_format.json
- exePath = r"C:\Program Files (x86)\Kingsoft\WPS Office\11.8.2.12085\office6\et"
- gl_button_x = 645
- gl_button_y = 45
- gl_refresh_button_x = 302
- gl_refresh_button_y = 87
- get_data_timeout_time = 30
- pointMinX = 200
- pointMaxX = 650
- pointMinY = 300
- pointMaxY = 550
- @hug.get('/mysteel_chemical/server')
- def mysteel_chemical_server():
- return 1
- @hug.get('/mysteel_chemical/refresh')
- def mysteel_chemical_refresh(FilePath):
- screen_width, screen_height = pyautogui.size()
- print("屏幕分辨率:{} x {}".format(screen_width, screen_height))
- pyautogui.FAILSAFE = False
-
- FilePath = FilePath.replace('"', '')
- pyautogui.hotkey('win', 'd')
-
-
-
-
-
-
- try:
- fileFullPath = FilePath
- print("fileFullPath start")
-
- fileFullPath = fileFullPath.replace("\\\\", "\\")
-
-
-
- print(fileFullPath)
-
-
-
-
- if os.path.exists(fileFullPath) and ".xlsx" in fileFullPath \
- and fileFullPath.find("~$") < 0 \
- and fileFullPath.find("template") < 0:
-
- file_name, file_ext = os.path.splitext(os.path.basename(fileFullPath))
- file_name_ext = file_name + file_ext
- print(file_name_ext)
- print(datetime.datetime.now())
- try:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- code = exePath + " " + fileFullPath
-
- autoit.run(code)
- autoit.win_wait_active(file_name_ext, timeout=20)
- autoit.win_move(file_name_ext, 0, 0, 1024, 768)
-
- print("监听成功了")
- except Exception as e:
- print("打开", fileFullPath, "失败:", e)
-
- screenshot = pyautogui.screenshot()
- imgPath = datetime.datetime.now().strftime("%Y%m%d%H%M%S")+"_screenshot_img.png"
- screenshot.save(imgPath)
- hwnd = win32gui.GetForegroundWindow()
- found_title = win32gui.GetWindowText(hwnd)
- print("窗口名称:", found_title)
- if found_title == "":
- print("窗口未打开")
- return
- if found_title.startswith(file_name_ext) == False:
- print("窗口与excel不一致,当前窗口:", found_title, ";excel:", file_name_ext)
- return
- autoit.win_move_by_handle(hwnd, 0, 0, 1024, 768)
-
-
- r = random.randint(2, 3)
- for i in range(r):
- pointX = random.randint(pointMinX, pointMaxX)
- pointY = random.randint(pointMinY, pointMaxY)
- print("随机点击", i + 1, "下;", "点击X:", pointX, ";Y:", pointY)
- pyautogui.moveTo(pointX, pointY, 0.5)
- pyautogui.click()
- time.sleep(1)
- print("start dataBtn")
- pyautogui.moveTo(gl_button_x, gl_button_y, 0.5)
- pyautogui.click()
- time.sleep(2)
- print("end dataBtn")
- pointX = random.randint(pointMinX, pointMaxX)
- pointY = random.randint(pointMinY, pointMaxY)
- pyautogui.moveTo(pointX, pointY)
- pyautogui.click()
- print("点击X:", pointX, ";Y:", pointY)
-
- sleepSec = random.randint(1, 3)
- time.sleep(sleepSec)
- pointX = random.randint(pointMinX, pointMaxX)
- pointY = random.randint(pointMinY, pointMaxY)
- pyautogui.moveTo(pointX, pointY)
- pyautogui.click()
- print("点击X:", pointX, ";Y:", pointY)
-
- sleepSec = random.randint(1, 3)
- time.sleep(sleepSec)
- print("start getCurrentPageData")
- pyautogui.moveTo(gl_refresh_button_x, gl_refresh_button_y, 1)
- pyautogui.click()
- time.sleep(1)
- print("end getCurrentPageData")
- pointX = random.randint(pointMinX, pointMaxX)
- pointY = random.randint(pointMinY, pointMaxY)
- pyautogui.moveTo(pointX, pointY, 0.5)
- pyautogui.click()
- print("点击X:", pointX, ";Y:", pointY)
-
- time.sleep(get_data_timeout_time)
- pyautogui.hotkey('ctrl', 's')
- time.sleep(1)
- pyautogui.hotkey('ctrl', 'w')
- return True
-
-
-
- else:
- print("ext err:" + fileFullPath)
-
- return True
- except Exception as e:
- print("Exception:")
- print(str(e))
- return False
- if __name__ == "__main__":
- app = __hug__.http.server()
- run(app=app, reloader=True, port=7007)
|