1
1
mirror of https://github.com/KenanZhu/AutoLibrary.git synced 2026-06-18 07:23:03 +08:00

Compare commits

...

2 Commits

Author SHA1 Message Date
KenanZhu 68b61b5c8c feat(AutoLib): new feature 'Auto Check-in' 2025-11-11 09:04:11 +08:00
KenanZhu fd5abb5f1e chore(LibReserve, LibCheckin): *
We use a more clear and structured output message
of reservation.

Complete the LibCheckin for the upcoming new
feature : 'Auto Check-in'
2025-11-11 09:00:20 +08:00
3 changed files with 96 additions and 11 deletions
+23 -1
View File
@@ -21,6 +21,7 @@ from LibChecker import LibChecker
from LibLogin import LibLogin from LibLogin import LibLogin
from LibLogout import LibLogout from LibLogout import LibLogout
from LibReserve import LibReserve from LibReserve import LibReserve
from LibCheckin import LibCheckin
from ConfigReader import ConfigReader from ConfigReader import ConfigReader
@@ -112,6 +113,7 @@ class AutoLib(MsgBase):
self.__lib_login = LibLogin(self._input_queue, self._output_queue, self.__driver) self.__lib_login = LibLogin(self._input_queue, self._output_queue, self.__driver)
self.__lib_logout = LibLogout(self._input_queue, self._output_queue, self.__driver) self.__lib_logout = LibLogout(self._input_queue, self._output_queue, self.__driver)
self.__lib_reserve = LibReserve(self._input_queue, self._output_queue, self.__driver) self.__lib_reserve = LibReserve(self._input_queue, self._output_queue, self.__driver)
self.__lib_checkin = LibCheckin(self._input_queue, self._output_queue, self.__driver)
def __waitResponseLoad( def __waitResponseLoad(
@@ -159,7 +161,7 @@ class AutoLib(MsgBase):
) -> int: ) -> int:
# result : 0 - success, 1 - failed, 2 - passed # result : 0 - success, 1 - failed, 2 - passed
result = 1 result = 2
# login # login
if not self.__lib_login.login( if not self.__lib_login.login(
@@ -188,6 +190,26 @@ class AutoLib(MsgBase):
self._showTrace(f"用户 {username} 预约失败 !") self._showTrace(f"用户 {username} 预约失败 !")
result = 1 result = 1
else: else:
self._showTrace(f"用户 {username} 无法预约,已跳过")
result = 2
# checkin
if run_mode["auto_checkin"] and result == 2:
if self.__lib_checker.canCheckin(reserve_info.get("date")):
if self.__lib_checkin.checkin(username):
self._showTrace(f"用户 {username} 签到成功 !")
result = 0
else:
self._showTrace(f"用户 {username} 签到失败 !")
result = 1
else:
self._showTrace(f"用户 {username} 无法签到,已跳过")
result = 2
# renewal
if run_mode["auto_renewal"] and result == 2:
if self.__lib_checker.canRenew(reserve_info.get("date")):
pass
else:
self._showTrace(f"用户 {username} 无法续约,已跳过")
result = 2 result = 2
# logout # logout
if not self.__lib_logout.logout( if not self.__lib_logout.logout(
+69 -2
View File
@@ -34,7 +34,74 @@ class LibCheckin(LibOperator):
def _waitResponseLoad( def _waitResponseLoad(
self, self
) -> bool: ) -> bool:
pass try:
WebDriverWait(self.__driver, 5).until(
EC.presence_of_element_located((By.CLASS_NAME, "ui_dialog"))
)
WebDriverWait(self.__driver, 2).until(
EC.presence_of_element_located((By.CLASS_NAME, "resultMessage"))
)
WebDriverWait(self.__driver, 2).until(
EC.element_to_be_clickable((By.CLASS_NAME, "btnOK"))
)
result_message_element = self.__driver.find_element(
By.CLASS_NAME, "resultMessage"
)
ok_btn = self.__driver.find_element(By.CLASS_NAME, "btnOK")
except:
self._showTrace("签到时发生未知错误 !")
return False
print(result_message_element)
result_message = result_message_element.text
if "签到成功" in result_message:
try:
detail_elements = self.__driver.find_elements(
By.CSS_SELECTOR, ".resultMessage dd"
)
except:
pass
if detail_elements:
details = [element.text for element in detail_elements if element.text.strip()]
if len(details) >= 5:
self._showTrace(f"\n"\
f" 签到成功 !\n"\
f" {details[1]}\n"\
f" {details[2]}\n"\
f" {details[3]}\n"\
f" {details[4]}")
else:
self._showTrace(
" 签到成功 !\n"\
" 未获取到签到详情 !")
ok_btn.click()
return True
else:
failure_reason = result_message.replace("签到失败", "").strip()
self._showTrace(f"签到失败: {failure_reason}")
ok_btn.click()
return False
def checkin(
self,
username: str
) -> bool:
if self.__driver is None:
self._showTrace("未提供有效 WebDriver 实例 !")
return False
try:
checkin_btn = WebDriverWait(self.__driver, 2).until(
EC.element_to_be_clickable((By.ID, "btnCheckIn"))
)
except:
self._showTrace(f"用户 {username} 签到界面加载失败 !")
return False
if "disabled" in checkin_btn.get_attribute("class"):
self._showTrace("签到按钮不可用, 可能不在场馆内, 请连接图书馆网络后重试")
return False
checkin_btn.click()
return self._waitResponseLoad()
+4 -8
View File
@@ -83,16 +83,12 @@ class LibReserve(LibOperator):
raise raise
if "预定好了" in title or "预约成功" in title or "操作成功" in title: if "预定好了" in title or "预约成功" in title or "操作成功" in title:
if len(contents) >= 6: if len(contents) >= 6:
date_val = contents[1].split(" : ")[1].strip() if " : " in contents[1] else contents[1].strip()
time_val = contents[2].split(" : ")[1].strip() if " : " in contents[2] else contents[2].strip()
seat_val = contents[3].split(" : ")[1].strip() if " : " in contents[3] else contents[3].strip()
checkin_val = contents[5].strip()
self._showTrace(f"\n"\ self._showTrace(f"\n"\
f" 预约成功 !\n"\ f" 预约成功 !\n"\
f" 预约日期: {date_val}, \n"\ f" {contents[1]}\n"\
f" 预约时间: {time_val}, \n"\ f" {contents[2]}\n"\
f" 预约座位: {seat_val}, \n"\ f" {contents[3]}\n"\
f" 签到时间: {checkin_val}") f" 签到时间 {contents[5]}")
else: else:
self._showTrace(f"\n"\ self._showTrace(f"\n"\
f" 预约成功 !\n"\ f" 预约成功 !\n"\