123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- import hug
- from bottle import route, run
- import pyautogui
- import random
- import time
- import os
- import pythoncom
- import win32gui, win32con, win32process
- import pyperclip
- import urllib.parse
- import autoit
- 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"
- @hug.get('/smm_chemical/server')
- def smm_server():
- return 1
- smm_button_x = 642
- smm_button_y = 53
- smm_refresh_select_button_x = 212
- smm_refresh_select_button_y = 119
- smm_refresh_button_x = 232
- smm_refresh_button_y = 178
- timeout_time = 15
- pointMinX = 200
- pointMaxX = 650
- pointMinY = 300
- pointMaxY = 550
- @hug.get('/smm_chemical/refresh')
- def smm_refresh(file_path):
- screen_width, screen_height = pyautogui.size()
- print("当前时间:{};当前屏幕分辨率:{} x {}".format(datetime.datetime.now(), screen_width, screen_height))
- pyautogui.FAILSAFE = False
- file_path = file_path.replace('"', '')
-
- pyautogui.hotkey('win', 'd')
- try:
- file_path = urllib.parse.unquote(file_path)
- fileFullPath = file_path
-
- fileFullPath = fileFullPath.replace("\\\\", "\\")
- print("文件路径:", fileFullPath)
- if not os.path.exists(fileFullPath):
- print("文件不存在")
- return
- 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
-
- 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)
-
-
- 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)
-
- r = random.randint(1, 2)
- time.sleep(r)
-
-
-
- pyautogui.moveTo(smm_button_x, smm_button_y, 0.5)
- pyautogui.click()
- time.sleep(1)
-
-
-
- pyautogui.moveTo(smm_refresh_select_button_x, smm_refresh_select_button_y, 0.5)
- pyautogui.click()
- time.sleep(1)
-
- print("开始刷新了")
-
-
- pyautogui.moveTo(smm_refresh_button_x, smm_refresh_button_y, 0.5)
- pyautogui.click()
- time.sleep(0.5)
- pointX = random.randint(pointMinX, pointMaxX)
- pointY = random.randint(pointMinY, pointMaxY)
-
- pyautogui.moveTo(pointX, pointY, 0.5)
-
- time.sleep(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)
|