hongtao3_login.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import os
  2. import pythoncom
  3. import time
  4. import random
  5. import pyautogui
  6. import win32gui, win32con
  7. from apscheduler.schedulers.blocking import BlockingScheduler
  8. # FilePath = "‪E:\\hz\\hongtao3_data\\"
  9. FilePath = "E:\\hz\\hongtao3_data\\"
  10. # FilePath = "D:\\"
  11. FileName = "login.xlsx"
  12. def check_excel_is_open():
  13. fileName = FilePath+FileName
  14. fileName = fileName.replace(r"\\", "\\")
  15. print(fileName)
  16. if os.path.exists(fileName):
  17. try:
  18. oldName = FilePath + FileName
  19. newName = FilePath + "tempfile.xls"
  20. print(oldName)
  21. print(newName)
  22. os.rename(oldName, newName)
  23. os.rename(newName, oldName)
  24. return False
  25. except OSError:
  26. print('login excel opened')
  27. return True
  28. return True
  29. else:
  30. print("file is not exist")
  31. return False
  32. def LoginFile(test):
  33. loginStatus = check_excel_is_open()
  34. print("loginStatus")
  35. print(loginStatus)
  36. if loginStatus is True: # login 文件打开状态
  37. print("loginStatus")
  38. print(loginStatus)
  39. else:
  40. try:
  41. # 回到桌面
  42. pyautogui.hotkey('win', 'd')
  43. time.sleep(1)
  44. pythoncom.CoInitialize()
  45. os.system("start " + FilePath + FileName)
  46. time.sleep(3)
  47. # et.dataBtn()
  48. # 最大化
  49. hwnd = win32gui.GetForegroundWindow()
  50. win32gui.ShowWindow(hwnd, win32con.SW_MAXIMIZE)
  51. time.sleep(1)
  52. # 随机暂停秒数
  53. r = random.randint(1, 3)
  54. time.sleep(r)
  55. print("点击了红桃三的按钮")
  56. ## 点击 红桃三的按钮
  57. #pointX = 595
  58. pointX = 521
  59. pointY = 42
  60. pyautogui.moveTo(pointX, pointY, 0.5)
  61. pyautogui.click(pointX, pointY)
  62. ## 点击登录按钮
  63. print("点击了登录按钮")
  64. r = random.randint(1, 2)
  65. time.sleep(r)
  66. pointX = 503
  67. pointY = 81
  68. pyautogui.moveTo(pointX, pointY, 0.5)
  69. pyautogui.click(pointX, pointY)
  70. ## 点击同花顺的登录弹框按钮
  71. print("点击了同花顺的登录弹框按钮")
  72. r = random.randint(1, 2)
  73. time.sleep(r)
  74. pointX = 970
  75. pointY = 574
  76. pyautogui.moveTo(pointX, pointY, 0.5)
  77. pyautogui.click(pointX, pointY)
  78. time.sleep(1)
  79. except Exception as e:
  80. print("open err")
  81. print(str(e))
  82. if __name__ == '__main__':
  83. # check_excel_is_open()
  84. scheduler = BlockingScheduler()
  85. scheduler.add_job(LoginFile, 'interval', seconds=20, args=['job1'], timezone='Asia/Shanghai')
  86. try:
  87. scheduler.start()
  88. except (KeyboardInterrupt, SystemExit):
  89. pass