123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- import hug
- from bottle import route, run
- import pyautogui
- import random
- import time
- import os
- import xlwings as xw
- import win32gui, win32con
- import urllib.parse
- hug.API(__name__).http.output_format = hug.output_format.json
- @hug.get('/mysteel_chemical/server')
- def mysteel_chemical_server():
- return 1
- @hug.get('/mysteel_chemical/refresh')
- def mysteel_chemical_refresh(FilePath):
- pyautogui.FAILSAFE = False
- # FilePath = urllib.parse.unquote(FilePath)
- FilePath = FilePath.replace('"', '')
- pyautogui.hotkey('win', 'd')
- time.sleep(2)
- moveX = 1100
- moveY = 600
- pyautogui.moveTo(moveX, moveY, 0.5)
- pyautogui.click(moveX, moveY)
- try:
- fileFullPath = FilePath
- print("fileFullPath start")
- print(fileFullPath)
- fileFullPath = fileFullPath.replace("\\\\", "\\")
- # fileFullPath.replace("\\", "\\")
- # fileFullPath.replace("ppp", "")
- print("fileFullPath")
- print(fileFullPath)
- # app = xw.App(visible=True, add_book=False)
- # app.display_alerts = False
- # app.screen_updating = True
- # print("init app")
- if os.path.exists(fileFullPath) and ".xlsx" in fileFullPath \
- and fileFullPath.find("~$") < 0 \
- and fileFullPath.find("template") < 0:
- x, y = 100, 1058
- pyautogui.click(x, y)
- time.sleep(4)
- pyautogui.typewrite(fileFullPath, 0.1)
- # print("open file:" + fileFullPath)
- # wb = app.books.open(fileFullPath)
- pyautogui.keyDown('enter')
- pyautogui.keyUp('enter')
- pyautogui.keyDown('enter')
- pyautogui.keyUp('enter')
- time.sleep(3)
- # open full screen
- hwnd = win32gui.GetForegroundWindow()
- win32gui.ShowWindow(hwnd, win32con.SW_MAXIMIZE)
- time.sleep(1)
- pyautogui.click(900, 600)
- time.sleep(1)
- pyautogui.click(900, 600)
- time.sleep(1)
- pyautogui.click(900, 600)
- time.sleep(1)
- print("start dataBtn")
- pointX = 500
- pointY = 40
- pyautogui.moveTo(pointX, pointY, 0.5)
- pyautogui.click(pointX, pointY)
- time.sleep(2)
- print("end dataBtn")
- pointX = random.randint(300, 1000)
- pointY = random.randint(350, 600)
- pyautogui.moveTo(pointX, pointY)
- pyautogui.click(pointX, pointY)
- sleepSec = random.randint(1, 3)
- time.sleep(sleepSec)
- pointX = random.randint(300, 1000)
- pointY = random.randint(350, 600)
- pyautogui.moveTo(pointX, pointY)
- pyautogui.click(pointX, pointY)
- sleepSec = random.randint(1, 3)
- time.sleep(sleepSec)
- pointX = 200
- pointY = 100
- pyautogui.moveTo(pointX, pointY, 1)
- pyautogui.click(pointX, pointY)
- time.sleep(1)
- print("end getCurrentPageData")
- pyautogui.moveTo(1300, 600, 0.5)
- pyautogui.click(1300, 600)
- time.sleep(22)
- pyautogui.hotkey('ctrl', 's')
- time.sleep(1)
- pyautogui.hotkey('ctrl', 'w')
- # wb.save()
- #
- # wb.close()
- else:
- print("ext err:" + fileFullPath)
- # app.kill()
- 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,host='0.0.0.0', port=7007)
|