From 88739d82b54f3063b83ce3f423c64b5b38a3c430 Mon Sep 17 00:00:00 2001 From: lrs <99574908+lrsgzs@users.noreply.github.com> Date: Fri, 30 Jun 2023 17:12:52 +0800 Subject: [PATCH] Add files via upload --- main.py | 27 +++++++++++++++++++++------ main.ui | 35 +++++++++++++++++++++++++++++++++-- main_ui.py | 13 ++++++++++++- 3 files changed, 66 insertions(+), 9 deletions(-) diff --git a/main.py b/main.py index 584ca0f..54db231 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,6 @@ import sys + + if sys.platform == "win32": import ctypes import winreg @@ -17,8 +19,16 @@ def is_admin(): from PySide2 import QtWidgets from selenium import webdriver + +from selenium.webdriver.edge import options as edge_option +from selenium.webdriver.chrome import options as chrome_option +from selenium.webdriver.firefox import options as firefox_option +from selenium.webdriver.safari import options as safari_option +from selenium.webdriver.ie import options as ie_option + from selenium.webdriver.support.select import Select from selenium.webdriver.common.by import By +import selenium.common.exceptions import time import os import pickle @@ -34,6 +44,7 @@ def __init__(self, parent=None): self.dialog = None self.driver = None + self.option = None self.info = {"date": "", "time": "", "ticket": "", "money": "", "id": ""} self.getticket.clicked.connect(self.get_ticket) @@ -121,7 +132,6 @@ def get_ticket(self): break webdrivers = [webdriver.ChromiumEdge, webdriver.Chrome, webdriver.Firefox, webdriver.Safari, webdriver.Ie] - self.driver = webdrivers[self.webdriver_select.currentIndex()]() self.driver.maximize_window() self.driver.get("https://www.globalinterpark.com/user/signin") @@ -136,15 +146,20 @@ def get_ticket(self): self.driver.get(self.url.toPlainText()) if self.is_open_timeup.checkState(): - timeup2 = self.timeup_hour.text() + ":" + str(int(self.timeup_min.text()) - 1) + ":55" + timeup2 = self.timeup_hour.text() + ":" + self.timeup_min.text() while True: - if time.strftime("%H:%M:%S") == timeup2: + if time.strftime("%H:%M") == timeup2: break if self.is_reload.checkState(): - self.driver.refresh() - time.sleep(2) + self.driver.set_page_load_timeout(int(float(self.timeout_sec.text()))) + try: + self.driver.refresh() + except selenium.common.exceptions.TimeoutException: + print("页面加载太拉了,停了算了") + self.driver.execute_script("window.stop()") self.driver.switch_to.frame(self.driver.find_element(By.ID, "product_detail_area")) + self.driver.set_page_load_timeout(300) wait_select_dom = self.driver.find_element(By.ID, "play_date") wait_select_dom.click() @@ -290,7 +305,7 @@ def get_ticket(self): f"座位: {self.info['ticket']}\n" \ f"花的钱: {self.info['money']}\n" \ f"ID: {self.info['id']}" - path = os.path.join(self.get_desktop(), txt_filename) + path = os.path.join(self.get_desktop_or_user_folder(), txt_filename) with open(path, "w", encoding="utf-8") as file: file.write(text) diff --git a/main.ui b/main.ui index 5aac450..2b83b24 100644 --- a/main.ui +++ b/main.ui @@ -7,7 +7,7 @@ 0 0 400 - 500 + 530 @@ -29,7 +29,7 @@ - # GlobalInterPark 抢票软件 + # GlobalInterPark 抢票软件2.0 Qt::MarkdownText @@ -959,6 +959,35 @@ 是否刷新 + + + + 10 + 500 + 141 + 21 + + + + 加载超时时间: 秒 + + + + + + 100 + 500 + 31 + 20 + + + + 123 + + + 3 + + label_18 label_12 label_8 @@ -1006,6 +1035,8 @@ start_min start_sec is_reload + label_22 + timeout_sec diff --git a/main_ui.py b/main_ui.py index 6a47080..46fa23b 100644 --- a/main_ui.py +++ b/main_ui.py @@ -4,7 +4,7 @@ class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") - MainWindow.resize(400, 500) + MainWindow.resize(400, 530) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.label = QtWidgets.QLabel(self.centralwidget) @@ -335,6 +335,13 @@ def setupUi(self, MainWindow): self.is_reload = QtWidgets.QCheckBox(self.centralwidget) self.is_reload.setGeometry(QtCore.QRect(50, 76, 71, 20)) self.is_reload.setObjectName("is_reload") + self.label_22 = QtWidgets.QLabel(self.centralwidget) + self.label_22.setGeometry(QtCore.QRect(10, 500, 141, 21)) + self.label_22.setObjectName("label_22") + self.timeout_sec = QtWidgets.QLineEdit(self.centralwidget) + self.timeout_sec.setGeometry(QtCore.QRect(100, 500, 31, 20)) + self.timeout_sec.setMaxLength(3) + self.timeout_sec.setObjectName("timeout_sec") self.label_18.raise_() self.label_12.raise_() self.label_8.raise_() @@ -382,6 +389,8 @@ def setupUi(self, MainWindow): self.start_min.raise_() self.start_sec.raise_() self.is_reload.raise_() + self.label_22.raise_() + self.timeout_sec.raise_() MainWindow.setCentralWidget(self.centralwidget) self.retranslateUi(MainWindow) @@ -451,3 +460,5 @@ def retranslateUi(self, MainWindow): self.days.setText(_translate("MainWindow", "1")) self.label_18.setText(_translate("MainWindow", " : :")) self.is_reload.setText(_translate("MainWindow", "是否刷新")) + self.label_22.setText(_translate("MainWindow", "加载超时时间: 秒")) + self.timeout_sec.setText(_translate("MainWindow", ""))