mysteel_refresh.py 3.6 KB

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