123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- import os
- import pythoncom
- import time
- import random
- import pyautogui
- import win32gui, win32con
- from apscheduler.schedulers.blocking import BlockingScheduler
- FilePath = "E:\\hz\\hongtao3_data\\"
- FileName = "login.xlsx"
- def check_excel_is_open():
- fileName = FilePath+FileName
- fileName = fileName.replace(r"\\", "\\")
- print(fileName)
- if os.path.exists(fileName):
- try:
- oldName = FilePath + FileName
- newName = FilePath + "tempfile.xls"
- print(oldName)
- print(newName)
- os.rename(oldName, newName)
- os.rename(newName, oldName)
- return False
- except OSError:
- print('login excel opened')
- return True
- return True
- else:
- print("file is not exist")
- return False
- def LoginFile(test):
- loginStatus = check_excel_is_open()
- print("loginStatus")
- print(loginStatus)
- if loginStatus is True:
- print("loginStatus")
- print(loginStatus)
- else:
- try:
-
- pyautogui.hotkey('win', 'd')
- time.sleep(1)
- pythoncom.CoInitialize()
- os.system("start " + FilePath + FileName)
- time.sleep(3)
-
-
- hwnd = win32gui.GetForegroundWindow()
- win32gui.ShowWindow(hwnd, win32con.SW_MAXIMIZE)
- time.sleep(1)
-
- r = random.randint(1, 3)
- time.sleep(r)
- print("点击了红桃三的按钮")
-
-
- pointX = 521
- pointY = 42
- pyautogui.moveTo(pointX, pointY, 0.5)
- pyautogui.click(pointX, pointY)
-
- print("点击了登录按钮")
- r = random.randint(1, 2)
- time.sleep(r)
- pointX = 503
- pointY = 81
- pyautogui.moveTo(pointX, pointY, 0.5)
- pyautogui.click(pointX, pointY)
-
- print("点击了同花顺的登录弹框按钮")
- r = random.randint(1, 2)
- time.sleep(r)
- pointX = 970
- pointY = 574
- pyautogui.moveTo(pointX, pointY, 0.5)
- pyautogui.click(pointX, pointY)
- time.sleep(1)
- except Exception as e:
- print("open err")
- print(str(e))
- if __name__ == '__main__':
-
- scheduler = BlockingScheduler()
- scheduler.add_job(LoginFile, 'interval', seconds=20, args=['job1'], timezone='Asia/Shanghai')
- try:
- scheduler.start()
- except (KeyboardInterrupt, SystemExit):
- pass
|