mirror of
https://github.com/KenanZhu/AutoLibrary.git
synced 2026-06-18 23:43:02 +08:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6cabddf0cd | |||
| 0322558339 | |||
| 703ee527ae | |||
| 9a925fecb6 | |||
| 189fddfb6a | |||
| c2d53a8b78 | |||
| b99431476a | |||
| 977c0835b7 |
+6
-6
@@ -8,10 +8,10 @@ build/
|
|||||||
dist/
|
dist/
|
||||||
model/*.onnx
|
model/*.onnx
|
||||||
driver/*.exe
|
driver/*.exe
|
||||||
gui/configs/*.json
|
src/gui/configs/*.json
|
||||||
gui/translators/qtbase_zh_CN.qm
|
src/gui/translators/qtbase_zh_CN.qm
|
||||||
gui/AutoLibraryResources.py
|
src/gui/AutoLibraryResources.py
|
||||||
gui/AutoLibraryResource.py
|
src/gui/AutoLibraryResource.py
|
||||||
gui/Ui_ALMainWindow.py
|
src/gui/Ui_ALMainWindow.py
|
||||||
gui/Ui_ALConfigWidget.py
|
src/gui/Ui_ALConfigWidget.py
|
||||||
Main.spec
|
Main.spec
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
|
|
||||||
# AutoLibrary
|
# AutoLibrary
|
||||||
|
|
||||||
请访问[AutoLibrary 网站](http://autolibrary.cv)
|
请访问[AutoLibrary 网站](http://autolibrary.cv)\
|
||||||
|
|
||||||
Please access the [AutoLibrary Website](http://autolibrary.cv)
|
Please access the [AutoLibrary Website](http://autolibrary.cv)
|
||||||
|
|||||||
Binary file not shown.
@@ -9,7 +9,7 @@ See the LICENSE file for details.
|
|||||||
"""
|
"""
|
||||||
import queue
|
import queue
|
||||||
|
|
||||||
from MsgBase import MsgBase
|
from base.MsgBase import MsgBase
|
||||||
|
|
||||||
|
|
||||||
class LibOperator(MsgBase):
|
class LibOperator(MsgBase):
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
"""
|
||||||
|
Base module for the AutoLibrary project.
|
||||||
|
|
||||||
|
Here are the classes and modules in this package:
|
||||||
|
- MsgBase: Base class for messages.\
|
||||||
|
- LibOperator: Base class for library operators.
|
||||||
|
"""
|
||||||
@@ -18,12 +18,12 @@ from PySide6.QtWidgets import (
|
|||||||
)
|
)
|
||||||
from PySide6.QtGui import QCloseEvent
|
from PySide6.QtGui import QCloseEvent
|
||||||
|
|
||||||
from .Ui_ALConfigWidget import Ui_ALConfigWidget
|
from gui.Ui_ALConfigWidget import Ui_ALConfigWidget
|
||||||
from .SeatMapWidget import SeatMapWidget
|
from gui.SeatMapWidget import SeatMapWidget
|
||||||
|
|
||||||
from .SeatMapTable import seats_maps
|
from gui.SeatMapTable import seats_maps
|
||||||
from ConfigReader import ConfigReader
|
from utils.ConfigReader import ConfigReader
|
||||||
from ConfigWriter import ConfigWriter
|
from utils.ConfigWriter import ConfigWriter
|
||||||
|
|
||||||
|
|
||||||
class ALConfigWidget(QWidget, Ui_ALConfigWidget):
|
class ALConfigWidget(QWidget, Ui_ALConfigWidget):
|
||||||
@@ -13,7 +13,7 @@ import time
|
|||||||
import queue
|
import queue
|
||||||
|
|
||||||
from PySide6.QtCore import (
|
from PySide6.QtCore import (
|
||||||
Qt, Signal, Slot, QTimer, QThread
|
Qt, Signal, Slot, QDir, QFileInfo, QTimer, QThread
|
||||||
)
|
)
|
||||||
from PySide6.QtWidgets import (
|
from PySide6.QtWidgets import (
|
||||||
QMainWindow, QMenu
|
QMainWindow, QMenu
|
||||||
@@ -27,8 +27,8 @@ from .ALConfigWidget import ALConfigWidget
|
|||||||
|
|
||||||
from . import AutoLibraryResource
|
from . import AutoLibraryResource
|
||||||
|
|
||||||
from AutoLib import AutoLib
|
from operators.AutoLib import AutoLib
|
||||||
from ConfigReader import ConfigReader
|
from utils.ConfigReader import ConfigReader
|
||||||
|
|
||||||
|
|
||||||
class AutoLibWorker(QThread):
|
class AutoLibWorker(QThread):
|
||||||
@@ -129,9 +129,11 @@ class ALMainWindow(QMainWindow, Ui_ALMainWindow):
|
|||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
self.__input_queue = queue.Queue()
|
self.__input_queue = queue.Queue()
|
||||||
self.__output_queue = queue.Queue()
|
self.__output_queue = queue.Queue()
|
||||||
|
script_path = sys.executable
|
||||||
|
script_dir = QFileInfo(script_path).absoluteDir()
|
||||||
self.__config_paths = {
|
self.__config_paths = {
|
||||||
"system": "",
|
"system": QDir.toNativeSeparators(script_dir.absoluteFilePath("system.json")),
|
||||||
"users": "",
|
"users": QDir.toNativeSeparators(script_dir.absoluteFilePath("users.json")),
|
||||||
}
|
}
|
||||||
self.__alConfigWidget = None
|
self.__alConfigWidget = None
|
||||||
self.__auto_lib_thread = None
|
self.__auto_lib_thread = None
|
||||||
@@ -18,7 +18,7 @@ from PySide6.QtWidgets import (
|
|||||||
from PySide6.QtGui import (
|
from PySide6.QtGui import (
|
||||||
QPainter, QWheelEvent, QCloseEvent
|
QPainter, QWheelEvent, QCloseEvent
|
||||||
)
|
)
|
||||||
from .SeatFrame import SeatFrame
|
from gui.SeatFrame import SeatFrame
|
||||||
|
|
||||||
|
|
||||||
class SeatMapWidget(QWidget):
|
class SeatMapWidget(QWidget):
|
||||||
|
Before Width: | Height: | Size: 785 KiB After Width: | Height: | Size: 785 KiB |
@@ -16,14 +16,14 @@ from selenium.webdriver.support.ui import WebDriverWait
|
|||||||
from selenium.webdriver.support import expected_conditions as EC
|
from selenium.webdriver.support import expected_conditions as EC
|
||||||
from selenium.webdriver.edge.service import Service
|
from selenium.webdriver.edge.service import Service
|
||||||
|
|
||||||
from MsgBase import MsgBase
|
from base.MsgBase import MsgBase
|
||||||
from LibChecker import LibChecker
|
from operators.LibChecker import LibChecker
|
||||||
from LibLogin import LibLogin
|
from operators.LibLogin import LibLogin
|
||||||
from LibLogout import LibLogout
|
from operators.LibLogout import LibLogout
|
||||||
from LibReserve import LibReserve
|
from operators.LibReserve import LibReserve
|
||||||
from LibCheckin import LibCheckin
|
from operators.LibCheckin import LibCheckin
|
||||||
|
|
||||||
from ConfigReader import ConfigReader
|
from utils.ConfigReader import ConfigReader
|
||||||
|
|
||||||
|
|
||||||
class AutoLib(MsgBase):
|
class AutoLib(MsgBase):
|
||||||
@@ -186,22 +186,18 @@ class AutoLib(MsgBase):
|
|||||||
if run_mode["auto_reserve"]:
|
if run_mode["auto_reserve"]:
|
||||||
if self.__lib_checker.canReserve(reserve_info.get("date")):
|
if self.__lib_checker.canReserve(reserve_info.get("date")):
|
||||||
if self.__lib_reserve.reserve(reserve_info):
|
if self.__lib_reserve.reserve(reserve_info):
|
||||||
self._showTrace(f"用户 {username} 预约成功 !")
|
|
||||||
result = 0
|
result = 0
|
||||||
else:
|
else:
|
||||||
self._showTrace(f"用户 {username} 预约失败 !")
|
|
||||||
result = 1
|
result = 1
|
||||||
else:
|
else:
|
||||||
self._showTrace(f"用户 {username} 无法预约,已跳过")
|
self._showTrace(f"用户 {username} 无法预约,已跳过")
|
||||||
result = 2
|
result = 2
|
||||||
# checkin
|
# checkin
|
||||||
if run_mode["auto_checkin"] and result == 2:
|
if run_mode["auto_checkin"] and result == 2:
|
||||||
if self.__lib_checker.canCheckin(reserve_info.get("date")):
|
if self.__lib_checker.canCheckin():
|
||||||
if self.__lib_checkin.checkin(username):
|
if self.__lib_checkin.checkin(username):
|
||||||
self._showTrace(f"用户 {username} 签到成功 !")
|
|
||||||
result = 0
|
result = 0
|
||||||
else:
|
else:
|
||||||
self._showTrace(f"用户 {username} 签到失败 !")
|
|
||||||
result = 1
|
result = 1
|
||||||
else:
|
else:
|
||||||
self._showTrace(f"用户 {username} 无法签到,已跳过")
|
self._showTrace(f"用户 {username} 无法签到,已跳过")
|
||||||
@@ -16,7 +16,7 @@ from selenium.webdriver.common.by import By
|
|||||||
from selenium.webdriver.support.ui import WebDriverWait
|
from selenium.webdriver.support.ui import WebDriverWait
|
||||||
from selenium.webdriver.support import expected_conditions as EC
|
from selenium.webdriver.support import expected_conditions as EC
|
||||||
|
|
||||||
from LibOperator import LibOperator
|
from base.LibOperator import LibOperator
|
||||||
|
|
||||||
|
|
||||||
class LibChecker(LibOperator):
|
class LibChecker(LibOperator):
|
||||||
@@ -25,7 +25,7 @@ class LibChecker(LibOperator):
|
|||||||
self,
|
self,
|
||||||
input_queue: queue.Queue,
|
input_queue: queue.Queue,
|
||||||
output_queue: queue.Queue,
|
output_queue: queue.Queue,
|
||||||
driver
|
driver: any
|
||||||
):
|
):
|
||||||
|
|
||||||
super().__init__(input_queue, output_queue)
|
super().__init__(input_queue, output_queue)
|
||||||
@@ -160,23 +160,6 @@ class LibChecker(LibOperator):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def __decodeReserveRecords(
|
|
||||||
self,
|
|
||||||
reservations
|
|
||||||
) -> list:
|
|
||||||
|
|
||||||
records = []
|
|
||||||
|
|
||||||
for reservation in reservations:
|
|
||||||
record = self.__decodeReserveRecord(reservation)
|
|
||||||
if record["date"] == "":
|
|
||||||
record = None
|
|
||||||
if record["time"] == {"begin": "", "end": ""}:
|
|
||||||
record = None
|
|
||||||
records.append(record)
|
|
||||||
return records
|
|
||||||
|
|
||||||
|
|
||||||
def __loadReserveRecords(
|
def __loadReserveRecords(
|
||||||
self
|
self
|
||||||
) -> list:
|
) -> list:
|
||||||
@@ -240,11 +223,15 @@ class LibChecker(LibOperator):
|
|||||||
reservations = self.__loadReserveRecords()
|
reservations = self.__loadReserveRecords()
|
||||||
if reservations is None:
|
if reservations is None:
|
||||||
return None
|
return None
|
||||||
records = self.__decodeReserveRecords(reservations[checked_count:])
|
for reservation in reservations[checked_count:]:
|
||||||
for record in records:
|
record = self.__decodeReserveRecord(reservation)
|
||||||
checked_count += 1
|
checked_count += 1
|
||||||
if record is None:
|
if record is None:
|
||||||
continue
|
continue
|
||||||
|
if record["date"] == "":
|
||||||
|
continue
|
||||||
|
if record["time"] == {"begin": "", "end": ""}:
|
||||||
|
continue
|
||||||
# record date is later than the given date, check the next one
|
# record date is later than the given date, check the next one
|
||||||
if datetime.strptime(record["date"], "%Y-%m-%d").date() >\
|
if datetime.strptime(record["date"], "%Y-%m-%d").date() >\
|
||||||
datetime.strptime(wanted_date, "%Y-%m-%d").date():
|
datetime.strptime(wanted_date, "%Y-%m-%d").date():
|
||||||
@@ -283,11 +270,11 @@ class LibChecker(LibOperator):
|
|||||||
|
|
||||||
|
|
||||||
def canCheckin(
|
def canCheckin(
|
||||||
self,
|
self
|
||||||
date: str
|
|
||||||
) -> bool:
|
) -> bool:
|
||||||
|
|
||||||
# have a reserved record in the given date
|
# only check the current date
|
||||||
|
date = time.strftime("%Y-%m-%d", time.localtime())
|
||||||
record = self.__getReserveRecord(date, "已预约")
|
record = self.__getReserveRecord(date, "已预约")
|
||||||
if record is not None:
|
if record is not None:
|
||||||
begin_time = record["time"]["begin"]
|
begin_time = record["time"]["begin"]
|
||||||
@@ -320,11 +307,11 @@ class LibChecker(LibOperator):
|
|||||||
|
|
||||||
|
|
||||||
def canRenew(
|
def canRenew(
|
||||||
self,
|
self
|
||||||
date: str
|
):
|
||||||
) -> bool:
|
|
||||||
|
|
||||||
# have a using record in the given date
|
# only check the current date
|
||||||
|
date = time.strftime("%Y-%m-%d", time.localtime())
|
||||||
record = self.__getReserveRecord(date, "使用中")
|
record = self.__getReserveRecord(date, "使用中")
|
||||||
if record is not None:
|
if record is not None:
|
||||||
end_time = record["time"]["end"]
|
end_time = record["time"]["end"]
|
||||||
@@ -338,9 +325,9 @@ class LibChecker(LibOperator):
|
|||||||
)
|
)
|
||||||
if abs(time_diff_seconds) < 120*60:
|
if abs(time_diff_seconds) < 120*60:
|
||||||
self._showTrace(f"{trace_msg}, 可以续约")
|
self._showTrace(f"{trace_msg}, 可以续约")
|
||||||
return True
|
return record
|
||||||
else:
|
else:
|
||||||
self._showTrace(f"{trace_msg}, 无法续约")
|
self._showTrace(f"{trace_msg}, 无法续约")
|
||||||
return False
|
return None
|
||||||
self._showTrace(f"用户在 {date} 没有有效预约记录, 无法续约")
|
self._showTrace(f"用户在 {date} 没有有效预约记录, 无法续约")
|
||||||
return False
|
return None
|
||||||
@@ -16,7 +16,7 @@ from selenium.webdriver.common.by import By
|
|||||||
from selenium.webdriver.support.ui import WebDriverWait
|
from selenium.webdriver.support.ui import WebDriverWait
|
||||||
from selenium.webdriver.support import expected_conditions as EC
|
from selenium.webdriver.support import expected_conditions as EC
|
||||||
|
|
||||||
from LibOperator import LibOperator
|
from base.LibOperator import LibOperator
|
||||||
|
|
||||||
|
|
||||||
class LibCheckin(LibOperator):
|
class LibCheckin(LibOperator):
|
||||||
@@ -25,7 +25,7 @@ class LibCheckin(LibOperator):
|
|||||||
self,
|
self,
|
||||||
input_queue: queue.Queue,
|
input_queue: queue.Queue,
|
||||||
output_queue: queue.Queue,
|
output_queue: queue.Queue,
|
||||||
driver
|
driver: any
|
||||||
):
|
):
|
||||||
|
|
||||||
super().__init__(input_queue, output_queue)
|
super().__init__(input_queue, output_queue)
|
||||||
@@ -54,7 +54,6 @@ class LibCheckin(LibOperator):
|
|||||||
except:
|
except:
|
||||||
self._showTrace("签到时发生未知错误 !")
|
self._showTrace("签到时发生未知错误 !")
|
||||||
return False
|
return False
|
||||||
print(result_message_element)
|
|
||||||
result_message = result_message_element.text
|
result_message = result_message_element.text
|
||||||
if "签到成功" in result_message:
|
if "签到成功" in result_message:
|
||||||
try:
|
try:
|
||||||
@@ -73,14 +72,16 @@ class LibCheckin(LibOperator):
|
|||||||
f" {details[3]}\n"\
|
f" {details[3]}\n"\
|
||||||
f" {details[4]}")
|
f" {details[4]}")
|
||||||
else:
|
else:
|
||||||
self._showTrace(
|
self._showTrace(f"\n"\
|
||||||
" 签到成功 !\n"\
|
" 签到成功 !\n"\
|
||||||
" 未获取到签到详情 !")
|
" 未获取到签到详情 !")
|
||||||
ok_btn.click()
|
ok_btn.click()
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
failure_reason = result_message.replace("签到失败", "").strip()
|
failure_reason = result_message.replace("签到失败", "").strip()
|
||||||
self._showTrace(f"签到失败: {failure_reason}")
|
self._showTrace(f"\n"\
|
||||||
|
" 签到失败 !\n"\
|
||||||
|
f" {failure_reason}")
|
||||||
ok_btn.click()
|
ok_btn.click()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -104,4 +105,9 @@ class LibCheckin(LibOperator):
|
|||||||
self._showTrace("签到按钮不可用, 可能不在场馆内, 请连接图书馆网络后重试")
|
self._showTrace("签到按钮不可用, 可能不在场馆内, 请连接图书馆网络后重试")
|
||||||
return False
|
return False
|
||||||
checkin_btn.click()
|
checkin_btn.click()
|
||||||
return self._waitResponseLoad()
|
if self._waitResponseLoad():
|
||||||
|
self._showTrace(f"用户 {username} 签到成功 !")
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
self._showTrace(f"用户 {username} 签到失败 !")
|
||||||
|
return False
|
||||||
@@ -16,7 +16,7 @@ from selenium.webdriver.common.by import By
|
|||||||
from selenium.webdriver.support.ui import WebDriverWait
|
from selenium.webdriver.support.ui import WebDriverWait
|
||||||
from selenium.webdriver.support import expected_conditions as EC
|
from selenium.webdriver.support import expected_conditions as EC
|
||||||
|
|
||||||
from LibOperator import LibOperator
|
from base.LibOperator import LibOperator
|
||||||
|
|
||||||
|
|
||||||
class LibCheckout(LibOperator):
|
class LibCheckout(LibOperator):
|
||||||
@@ -25,7 +25,7 @@ class LibCheckout(LibOperator):
|
|||||||
self,
|
self,
|
||||||
input_queue: queue.Queue,
|
input_queue: queue.Queue,
|
||||||
output_queue: queue.Queue,
|
output_queue: queue.Queue,
|
||||||
driver
|
driver: any
|
||||||
):
|
):
|
||||||
|
|
||||||
super().__init__(input_queue, output_queue)
|
super().__init__(input_queue, output_queue)
|
||||||
@@ -17,7 +17,7 @@ from selenium.webdriver.common.by import By
|
|||||||
from selenium.webdriver.support.ui import WebDriverWait
|
from selenium.webdriver.support.ui import WebDriverWait
|
||||||
from selenium.webdriver.support import expected_conditions as EC
|
from selenium.webdriver.support import expected_conditions as EC
|
||||||
|
|
||||||
from LibOperator import LibOperator
|
from base.LibOperator import LibOperator
|
||||||
|
|
||||||
|
|
||||||
class LibLogin(LibOperator):
|
class LibLogin(LibOperator):
|
||||||
@@ -26,7 +26,7 @@ class LibLogin(LibOperator):
|
|||||||
self,
|
self,
|
||||||
input_queue: queue.Queue,
|
input_queue: queue.Queue,
|
||||||
output_queue: queue.Queue,
|
output_queue: queue.Queue,
|
||||||
driver
|
driver: any
|
||||||
):
|
):
|
||||||
|
|
||||||
super().__init__(input_queue, output_queue)
|
super().__init__(input_queue, output_queue)
|
||||||
@@ -13,7 +13,7 @@ from selenium.webdriver.common.by import By
|
|||||||
from selenium.webdriver.support.ui import WebDriverWait
|
from selenium.webdriver.support.ui import WebDriverWait
|
||||||
from selenium.webdriver.support import expected_conditions as EC
|
from selenium.webdriver.support import expected_conditions as EC
|
||||||
|
|
||||||
from LibOperator import LibOperator
|
from base.LibOperator import LibOperator
|
||||||
|
|
||||||
|
|
||||||
class LibLogout(LibOperator):
|
class LibLogout(LibOperator):
|
||||||
@@ -22,7 +22,7 @@ class LibLogout(LibOperator):
|
|||||||
self,
|
self,
|
||||||
input_queue: queue.Queue,
|
input_queue: queue.Queue,
|
||||||
output_queue: queue.Queue,
|
output_queue: queue.Queue,
|
||||||
driver
|
driver: any
|
||||||
):
|
):
|
||||||
|
|
||||||
super().__init__(input_queue, output_queue)
|
super().__init__(input_queue, output_queue)
|
||||||
@@ -8,9 +8,15 @@ You may use, modify, and distribute this file under the terms of the MIT License
|
|||||||
See the LICENSE file for details.
|
See the LICENSE file for details.
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
|
import time
|
||||||
import queue
|
import queue
|
||||||
|
|
||||||
from LibOperator import LibOperator
|
from datetime import datetime, timedelta
|
||||||
|
from selenium.webdriver.common.by import By
|
||||||
|
from selenium.webdriver.support.ui import WebDriverWait
|
||||||
|
from selenium.webdriver.support import expected_conditions as EC
|
||||||
|
|
||||||
|
from base.LibOperator import LibOperator
|
||||||
|
|
||||||
|
|
||||||
class LibRenew(LibOperator):
|
class LibRenew(LibOperator):
|
||||||
@@ -19,7 +25,7 @@ class LibRenew(LibOperator):
|
|||||||
self,
|
self,
|
||||||
input_queue: queue.Queue,
|
input_queue: queue.Queue,
|
||||||
output_queue: queue.Queue,
|
output_queue: queue.Queue,
|
||||||
driver
|
driver: any
|
||||||
):
|
):
|
||||||
|
|
||||||
super().__init__(input_queue, output_queue)
|
super().__init__(input_queue, output_queue)
|
||||||
@@ -16,7 +16,7 @@ from selenium.webdriver.common.by import By
|
|||||||
from selenium.webdriver.support.ui import WebDriverWait
|
from selenium.webdriver.support.ui import WebDriverWait
|
||||||
from selenium.webdriver.support import expected_conditions as EC
|
from selenium.webdriver.support import expected_conditions as EC
|
||||||
|
|
||||||
from LibOperator import LibOperator
|
from base.LibOperator import LibOperator
|
||||||
|
|
||||||
|
|
||||||
class LibReserve(LibOperator):
|
class LibReserve(LibOperator):
|
||||||
@@ -25,7 +25,7 @@ class LibReserve(LibOperator):
|
|||||||
self,
|
self,
|
||||||
input_queue: queue.Queue,
|
input_queue: queue.Queue,
|
||||||
output_queue: queue.Queue,
|
output_queue: queue.Queue,
|
||||||
driver
|
driver: any
|
||||||
):
|
):
|
||||||
|
|
||||||
super().__init__(input_queue, output_queue)
|
super().__init__(input_queue, output_queue)
|
||||||
@@ -187,12 +187,13 @@ class LibReserve(LibOperator):
|
|||||||
reserve_info: dict
|
reserve_info: dict
|
||||||
) -> bool:
|
) -> bool:
|
||||||
|
|
||||||
if reserve_info.get("expect_duration") is None:
|
|
||||||
reserve_info["expect_duration"] = 4
|
|
||||||
self._showTrace("预约持续时间未指定, 使用默认时长为 4 小时")
|
|
||||||
if reserve_info.get("satisfy_duration") is None:
|
if reserve_info.get("satisfy_duration") is None:
|
||||||
reserve_info["satisfy_duration"] = True
|
reserve_info["satisfy_duration"] = True
|
||||||
self._showTrace("预约满足时长要求未指定, 默认满足")
|
self._showTrace("预约满足时长要求未指定, 默认满足")
|
||||||
|
if reserve_info["satisfy_duration"]:
|
||||||
|
if reserve_info.get("expect_duration") is None:
|
||||||
|
reserve_info["expect_duration"] = 4
|
||||||
|
self._showTrace("需要满足预约持续时间, 但未指定, 使用默认时长为 4 小时")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@@ -234,7 +235,7 @@ class LibReserve(LibOperator):
|
|||||||
# if end time is earlier than begin_time, exchange them
|
# if end time is earlier than begin_time, exchange them
|
||||||
if end_mins < begin_mins:
|
if end_mins < begin_mins:
|
||||||
self._showTrace(
|
self._showTrace(
|
||||||
f"结束时间 {end_time['time']} 早于开始时间 {begin_time['time']}, 自动交换"
|
f"结束时间 {end_time['time']} 早于开始时间 {begin_time['time']}, 尝试交换时间"
|
||||||
)
|
)
|
||||||
reserve_info["end_time"] = begin_time
|
reserve_info["end_time"] = begin_time
|
||||||
reserve_info["begin_time"] = end_time
|
reserve_info["begin_time"] = end_time
|
||||||
@@ -261,10 +262,9 @@ class LibReserve(LibOperator):
|
|||||||
if end_mins - begin_mins > 8*60:
|
if end_mins - begin_mins > 8*60:
|
||||||
self._showTrace(
|
self._showTrace(
|
||||||
f"该用户未设置优先满足时长要求, 但是检查到预约持续时间 "
|
f"该用户未设置优先满足时长要求, 但是检查到预约持续时间 "
|
||||||
f"{int((end_mins - begin_mins)/60)} 小时 "
|
f"{float((end_mins - begin_mins)/60)} 小时 "
|
||||||
f"超出最大时长 8 小时, 自动设置为 8 小时"
|
f"超出最大时长 8 小时, 自动设置为 8 小时"
|
||||||
)
|
)
|
||||||
reserve_info["expect_duration"] = 8
|
|
||||||
reserve_info["end_time"]["time"] = self.__minsToTime(begin_mins + 8*60)
|
reserve_info["end_time"]["time"] = self.__minsToTime(begin_mins + 8*60)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -324,11 +324,52 @@ class LibReserve(LibOperator):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def __clickElementByJS(
|
||||||
|
self,
|
||||||
|
trigger_locator_id: str,
|
||||||
|
option_query_selector: str,
|
||||||
|
fail_msg: str,
|
||||||
|
success_msg: str,
|
||||||
|
) -> bool:
|
||||||
|
|
||||||
|
script = f"""
|
||||||
|
try {{
|
||||||
|
var trigger = document.getElementById('{trigger_locator_id}');
|
||||||
|
if (trigger) {{
|
||||||
|
trigger.click();
|
||||||
|
var option = document.querySelector("{option_query_selector}");
|
||||||
|
if (option) {{
|
||||||
|
option.click();
|
||||||
|
return true;
|
||||||
|
}}
|
||||||
|
return false;
|
||||||
|
}}
|
||||||
|
return false;
|
||||||
|
}} catch (e) {{
|
||||||
|
return false;
|
||||||
|
}}
|
||||||
|
"""
|
||||||
|
result = self.__driver.execute_script(script)
|
||||||
|
time.sleep(0.1)
|
||||||
|
if result:
|
||||||
|
self._showTrace(success_msg)
|
||||||
|
else:
|
||||||
|
self._showTrace(fail_msg)
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
def __selectDate(
|
def __selectDate(
|
||||||
self,
|
self,
|
||||||
date_str: str
|
date_str: str
|
||||||
) -> bool:
|
) -> bool:
|
||||||
|
|
||||||
|
if self.__clickElementByJS(
|
||||||
|
trigger_locator_id="onDate_select",
|
||||||
|
option_query_selector=f"p#options_onDate a[value='{date_str}']",
|
||||||
|
success_msg=f"日期 {date_str} 选择成功 !",
|
||||||
|
fail_msg=f"选择日期失败 ! : {date_str} 不可用"
|
||||||
|
):
|
||||||
|
return True
|
||||||
return self.__clickElement(
|
return self.__clickElement(
|
||||||
trigger_locator=(By.ID, "onDate_select"),
|
trigger_locator=(By.ID, "onDate_select"),
|
||||||
option_locator=(By.XPATH, f"//p[@id='options_onDate']/a[@value='{date_str}']"),
|
option_locator=(By.XPATH, f"//p[@id='options_onDate']/a[@value='{date_str}']"),
|
||||||
@@ -342,12 +383,20 @@ class LibReserve(LibOperator):
|
|||||||
place: str
|
place: str
|
||||||
) -> bool:
|
) -> bool:
|
||||||
|
|
||||||
actual_place = "1" if place == "图书馆" else "1"
|
place = "1" # the library only have this place :)
|
||||||
|
display_place = "图书馆"
|
||||||
|
if self.__clickElementByJS(
|
||||||
|
trigger_locator_id="display_building",
|
||||||
|
option_query_selector=f"p#options_building a[value='{place}']",
|
||||||
|
success_msg=f"预约场所 {display_place} 选择成功 !",
|
||||||
|
fail_msg=f"选择预约场所失败 ! : {display_place} 不可用"
|
||||||
|
):
|
||||||
|
return True
|
||||||
return self.__clickElement(
|
return self.__clickElement(
|
||||||
trigger_locator=(By.ID, "display_building"),
|
trigger_locator=(By.ID, "display_building"),
|
||||||
option_locator=(By.XPATH, f"//p[@id='options_building']/a[@value='{actual_place}']"),
|
option_locator=(By.XPATH, f"//p[@id='options_building']/a[@value='{place}']"),
|
||||||
success_msg=f"预约场所 {place} 选择成功 !",
|
success_msg=f"预约场所 {display_place} 选择成功 !",
|
||||||
fail_msg=f"选择预约场所失败 ! : {place} 不可用"
|
fail_msg=f"选择预约场所失败 ! : {display_place} 不可用"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -357,6 +406,13 @@ class LibReserve(LibOperator):
|
|||||||
) -> bool:
|
) -> bool:
|
||||||
|
|
||||||
display_floor = self.__floor_map.get(floor)
|
display_floor = self.__floor_map.get(floor)
|
||||||
|
if self.__clickElementByJS(
|
||||||
|
trigger_locator_id="floor_select",
|
||||||
|
option_query_selector=f"p#options_floor a[value='{floor}']",
|
||||||
|
success_msg=f"楼层 {display_floor} 选择成功 !",
|
||||||
|
fail_msg=f"选择楼层失败 ! : {display_floor} 不可用"
|
||||||
|
):
|
||||||
|
return True
|
||||||
return self.__clickElement(
|
return self.__clickElement(
|
||||||
trigger_locator=(By.ID, "floor_select"),
|
trigger_locator=(By.ID, "floor_select"),
|
||||||
option_locator=(By.XPATH, f"//p[@id='options_floor']/a[@value='{floor}']"),
|
option_locator=(By.XPATH, f"//p[@id='options_floor']/a[@value='{floor}']"),
|
||||||
@@ -371,12 +427,24 @@ class LibReserve(LibOperator):
|
|||||||
) -> bool:
|
) -> bool:
|
||||||
|
|
||||||
display_room = self.__room_map.get(room)
|
display_room = self.__room_map.get(room)
|
||||||
return self.__clickElement(
|
# find room
|
||||||
trigger_locator=(By.ID, f"room_{room}"),
|
try:
|
||||||
option_locator=None,
|
WebDriverWait(self.__driver, 2).until(
|
||||||
success_msg=f"房间 {display_room} 选择成功 !",
|
EC.element_to_be_clickable((By.ID, "findRoom"))
|
||||||
fail_msg=f"选择房间失败 ! : {display_room} 不可用"
|
).click()
|
||||||
)
|
except:
|
||||||
|
self._showTrace("加载房间/区域失败 !")
|
||||||
|
return False
|
||||||
|
# select room
|
||||||
|
try:
|
||||||
|
WebDriverWait(self.__driver, 2).until(
|
||||||
|
EC.element_to_be_clickable((By.ID, f"room_{room}"))
|
||||||
|
).click()
|
||||||
|
self._showTrace(f"房间 {display_room} 选择成功 !")
|
||||||
|
return True
|
||||||
|
except:
|
||||||
|
self._showTrace(f"选择房间失败 ! : {display_room} 不可用")
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def __selectSeat(
|
def __selectSeat(
|
||||||
@@ -509,6 +577,7 @@ class LibReserve(LibOperator):
|
|||||||
expect_begin_time = actual_begin_time = begin_time["time"]
|
expect_begin_time = actual_begin_time = begin_time["time"]
|
||||||
expect_end_time = actual_end_time = end_time["time"]
|
expect_end_time = actual_end_time = end_time["time"]
|
||||||
expect_begin_mins = self.__timeToMins(expect_begin_time)
|
expect_begin_mins = self.__timeToMins(expect_begin_time)
|
||||||
|
actual_begin_mins = expect_begin_mins
|
||||||
expect_end_mins = self.__timeToMins(expect_end_time)
|
expect_end_mins = self.__timeToMins(expect_end_time)
|
||||||
|
|
||||||
# select the begin time
|
# select the begin time
|
||||||
@@ -522,11 +591,18 @@ class LibReserve(LibOperator):
|
|||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
actual_begin_time = self.__minsToTime(expect_begin_mins)
|
actual_begin_time = self.__minsToTime(expect_begin_mins)
|
||||||
|
actual_begin_mins = self.__timeToMins(actual_begin_time)
|
||||||
# if 'satisfy_duration' is True.
|
# if 'satisfy_duration' is True.
|
||||||
# select the end time based on the begin time
|
# select the end time based on the begin time
|
||||||
# (because it may be changed under the 'max time diff' strategy) and expect duration.
|
# (because it may be changed under the 'max time diff' strategy) and expect duration.
|
||||||
if satisfy_duration:
|
if satisfy_duration:
|
||||||
expect_end_mins = int(expect_begin_mins + expct_duration*60)
|
expect_end_mins = int(actual_begin_mins + expct_duration*60)
|
||||||
|
if expect_end_mins > self.__timeToMins("23:30"):
|
||||||
|
expect_end_mins = self.__timeToMins("23:30")
|
||||||
|
self._showTrace(
|
||||||
|
f"预约持续时间 {expct_duration} 小时, 超过最大预约时间 23:30, 自动调整为 23:30"
|
||||||
|
)
|
||||||
|
expect_end_time = self.__minsToTime(expect_end_mins)
|
||||||
self._showTrace(
|
self._showTrace(
|
||||||
f"需要满足期望预约持续时间: {expct_duration} 小时, "\
|
f"需要满足期望预约持续时间: {expct_duration} 小时, "\
|
||||||
f"根据开始时间 {actual_begin_time} 计算结束时间: {self.__minsToTime(expect_end_mins)}"
|
f"根据开始时间 {actual_begin_time} 计算结束时间: {self.__minsToTime(expect_end_mins)}"
|
||||||
@@ -572,22 +648,13 @@ class LibReserve(LibOperator):
|
|||||||
except:
|
except:
|
||||||
self._showTrace(f"加载预约选座页面失败 !")
|
self._showTrace(f"加载预约选座页面失败 !")
|
||||||
return False
|
return False
|
||||||
# date, place, floor
|
# date, place, floor, room
|
||||||
if not self.__selectDate(reserve_info["date"]):
|
if not self.__selectDate(reserve_info["date"]):
|
||||||
return False
|
return False
|
||||||
if not self.__selectPlace(reserve_info["place"]):
|
if not self.__selectPlace(reserve_info["place"]):
|
||||||
return False
|
return False
|
||||||
if not self.__selectFloor(reserve_info["floor"]):
|
if not self.__selectFloor(reserve_info["floor"]):
|
||||||
return False
|
return False
|
||||||
# room find
|
|
||||||
try:
|
|
||||||
WebDriverWait(self.__driver, 2).until(
|
|
||||||
EC.element_to_be_clickable((By.ID, "findRoom"))
|
|
||||||
).click()
|
|
||||||
except:
|
|
||||||
self._showTrace("加载房间/区域失败 !")
|
|
||||||
return False
|
|
||||||
# room
|
|
||||||
if not self.__selectRoom(reserve_info["room"]):
|
if not self.__selectRoom(reserve_info["room"]):
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
@@ -615,4 +682,8 @@ class LibReserve(LibOperator):
|
|||||||
self._showTrace(f"预约提交失败 !")
|
self._showTrace(f"预约提交失败 !")
|
||||||
if not submit_reserve and have_hover_on_page:
|
if not submit_reserve and have_hover_on_page:
|
||||||
self.__driver.refresh()
|
self.__driver.refresh()
|
||||||
|
if reserve_success:
|
||||||
|
self._showTrace(f"用户 {reserve_info['username']} 预约成功 !")
|
||||||
|
else:
|
||||||
|
self._showTrace(f"用户 {reserve_info['username']} 预约失败 !")
|
||||||
return reserve_success
|
return reserve_success
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
"""
|
||||||
|
Operators module for the AutoLibrary project.
|
||||||
|
|
||||||
|
Here are the classes and modules in this package:
|
||||||
|
- AutoLib: AutoLibrary operator.
|
||||||
|
- LibLogin: Library operator for logging in.
|
||||||
|
- LibLogout: Library operator for logging out.
|
||||||
|
- LibReserve: Library operator for reserving seat.
|
||||||
|
- LibCheckin: Library operator for checking in seat.
|
||||||
|
- LibCheckout: Library operator for checking out seat.
|
||||||
|
- LibRenew: Library operator for renewing seat.
|
||||||
|
"""
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
"""
|
||||||
|
Utils module for the AutoLibrary project.
|
||||||
|
|
||||||
|
Here are the classes and modules in this package:
|
||||||
|
- ConfigReader: Configuration reader class for the AutoLibrary project.
|
||||||
|
- ConfigWriter: Configuration writer class for the AutoLibrary project.
|
||||||
|
"""
|
||||||
Reference in New Issue
Block a user