mysteel_refresh.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import hug
  2. from bottle import route, run
  3. import pyautogui
  4. import random
  5. import time
  6. import os
  7. import win32gui, win32con
  8. import urllib.parse
  9. hug.API(__name__).http.output_format = hug.output_format.json
  10. @hug.get('/mysteel_chemical/server')
  11. def mysteel_chemical_server():
  12. return 1
  13. @hug.get('/mysteel_chemical/refresh')
  14. def mysteel_chemical_refresh(FilePath):
  15. pyautogui.FAILSAFE = False
  16. # FilePath = urllib.parse.unquote(FilePath)
  17. FilePath = FilePath.replace('"', '')
  18. pyautogui.hotkey('win', 'd')
  19. time.sleep(2)
  20. moveX = 1100
  21. moveY = 600
  22. pyautogui.moveTo(moveX, moveY, 0.5)
  23. pyautogui.click(moveX, moveY)
  24. try:
  25. fileFullPath = FilePath
  26. print("fileFullPath start")
  27. print(fileFullPath)
  28. fileFullPath = fileFullPath.replace("\\\\", "\\")
  29. # fileFullPath.replace("\\", "\\")
  30. # fileFullPath.replace("ppp", "")
  31. print("fileFullPath")
  32. print(fileFullPath)
  33. # app = xw.App(visible=True, add_book=False)
  34. # app.display_alerts = False
  35. # app.screen_updating = True
  36. # print("init app")
  37. if os.path.exists(fileFullPath) and ".xlsx" in fileFullPath \
  38. and fileFullPath.find("~$") < 0 \
  39. and fileFullPath.find("template") < 0:
  40. x, y = 100, 1058
  41. pyautogui.click(x, y)
  42. time.sleep(4)
  43. pyautogui.typewrite(fileFullPath, 0.1)
  44. # print("open file:" + fileFullPath)
  45. # wb = app.books.open(fileFullPath)
  46. pyautogui.keyDown('enter')
  47. pyautogui.keyUp('enter')
  48. pyautogui.keyDown('enter')
  49. pyautogui.keyUp('enter')
  50. time.sleep(3)
  51. # open full screen
  52. hwnd = win32gui.GetForegroundWindow()
  53. win32gui.ShowWindow(hwnd, win32con.SW_MAXIMIZE)
  54. time.sleep(1)
  55. pyautogui.click(900, 600)
  56. time.sleep(1)
  57. pyautogui.click(900, 600)
  58. time.sleep(1)
  59. pyautogui.click(900, 600)
  60. time.sleep(1)
  61. print("start dataBtn")
  62. pointX = 500
  63. pointY = 40
  64. pyautogui.moveTo(pointX, pointY, 0.5)
  65. pyautogui.click(pointX, pointY)
  66. time.sleep(2)
  67. print("end dataBtn")
  68. pointX = random.randint(300, 1000)
  69. pointY = random.randint(350, 600)
  70. pyautogui.moveTo(pointX, pointY)
  71. pyautogui.click(pointX, pointY)
  72. sleepSec = random.randint(1, 3)
  73. time.sleep(sleepSec)
  74. pointX = random.randint(300, 1000)
  75. pointY = random.randint(350, 600)
  76. pyautogui.moveTo(pointX, pointY)
  77. pyautogui.click(pointX, pointY)
  78. sleepSec = random.randint(1, 3)
  79. time.sleep(sleepSec)
  80. pointX = 200
  81. pointY = 100
  82. pyautogui.moveTo(pointX, pointY, 1)
  83. pyautogui.click(pointX, pointY)
  84. time.sleep(1)
  85. print("end getCurrentPageData")
  86. pyautogui.moveTo(1300, 600, 0.5)
  87. pyautogui.click(1300, 600)
  88. time.sleep(22)
  89. pyautogui.hotkey('ctrl', 's')
  90. time.sleep(1)
  91. pyautogui.hotkey('ctrl', 'w')
  92. # wb.save()
  93. #
  94. # wb.close()
  95. else:
  96. print("ext err:" + fileFullPath)
  97. # app.kill()
  98. return True
  99. except Exception as e:
  100. print("Exception:")
  101. print(str(e))
  102. return False
  103. if __name__ == "__main__":
  104. app = __hug__.http.server()
  105. run(app=app, reloader=True,host='0.0.0.0', port=7007)