Jelajahi Sumber

新增钢联指标刷新

tuoling805 1 tahun lalu
melakukan
b3937c1938
1 mengubah file dengan 126 tambahan dan 0 penghapusan
  1. 126 0
      mysteel_refresh.py

+ 126 - 0
mysteel_refresh.py

@@ -0,0 +1,126 @@
+import hug
+from bottle import route, run
+import excel_tool as et
+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, port=7007)