mysteel_refresh.py 3.6 KB

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