mirror of
https://github.com/KenanZhu/AutoLibrary.git
synced 2026-06-18 07:23:03 +08:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6cabddf0cd | |||
| 0322558339 |
@@ -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} 无法签到,已跳过")
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
@@ -577,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
|
||||||
@@ -590,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)}"
|
||||||
@@ -674,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
|
||||||
Reference in New Issue
Block a user