mirror of
https://github.com/KenanZhu/AutoLibrary.git
synced 2026-06-18 15:33:03 +08:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 703ee527ae | |||
| 9a925fecb6 | |||
| 189fddfb6a | |||
| c2d53a8b78 |
+6
-6
@@ -8,10 +8,10 @@ build/
|
||||
dist/
|
||||
model/*.onnx
|
||||
driver/*.exe
|
||||
gui/configs/*.json
|
||||
gui/translators/qtbase_zh_CN.qm
|
||||
gui/AutoLibraryResources.py
|
||||
gui/AutoLibraryResource.py
|
||||
gui/Ui_ALMainWindow.py
|
||||
gui/Ui_ALConfigWidget.py
|
||||
src/gui/configs/*.json
|
||||
src/gui/translators/qtbase_zh_CN.qm
|
||||
src/gui/AutoLibraryResources.py
|
||||
src/gui/AutoLibraryResource.py
|
||||
src/gui/Ui_ALMainWindow.py
|
||||
src/gui/Ui_ALConfigWidget.py
|
||||
Main.spec
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
|
||||
# AutoLibrary
|
||||
|
||||
请访问[AutoLibrary 网站](http://autolibrary.cv)
|
||||
|
||||
请访问[AutoLibrary 网站](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
|
||||
|
||||
from MsgBase import MsgBase
|
||||
from base.MsgBase import 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 .Ui_ALConfigWidget import Ui_ALConfigWidget
|
||||
from .SeatMapWidget import SeatMapWidget
|
||||
from gui.Ui_ALConfigWidget import Ui_ALConfigWidget
|
||||
from gui.SeatMapWidget import SeatMapWidget
|
||||
|
||||
from .SeatMapTable import seats_maps
|
||||
from ConfigReader import ConfigReader
|
||||
from ConfigWriter import ConfigWriter
|
||||
from gui.SeatMapTable import seats_maps
|
||||
from utils.ConfigReader import ConfigReader
|
||||
from utils.ConfigWriter import ConfigWriter
|
||||
|
||||
|
||||
class ALConfigWidget(QWidget, Ui_ALConfigWidget):
|
||||
@@ -27,8 +27,8 @@ from .ALConfigWidget import ALConfigWidget
|
||||
|
||||
from . import AutoLibraryResource
|
||||
|
||||
from AutoLib import AutoLib
|
||||
from ConfigReader import ConfigReader
|
||||
from operators.AutoLib import AutoLib
|
||||
from utils.ConfigReader import ConfigReader
|
||||
|
||||
|
||||
class AutoLibWorker(QThread):
|
||||
@@ -18,7 +18,7 @@ from PySide6.QtWidgets import (
|
||||
from PySide6.QtGui import (
|
||||
QPainter, QWheelEvent, QCloseEvent
|
||||
)
|
||||
from .SeatFrame import SeatFrame
|
||||
from gui.SeatFrame import SeatFrame
|
||||
|
||||
|
||||
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.edge.service import Service
|
||||
|
||||
from MsgBase import MsgBase
|
||||
from LibChecker import LibChecker
|
||||
from LibLogin import LibLogin
|
||||
from LibLogout import LibLogout
|
||||
from LibReserve import LibReserve
|
||||
from LibCheckin import LibCheckin
|
||||
from base.MsgBase import MsgBase
|
||||
from operators.LibChecker import LibChecker
|
||||
from operators.LibLogin import LibLogin
|
||||
from operators.LibLogout import LibLogout
|
||||
from operators.LibReserve import LibReserve
|
||||
from operators.LibCheckin import LibCheckin
|
||||
|
||||
from ConfigReader import ConfigReader
|
||||
from utils.ConfigReader import ConfigReader
|
||||
|
||||
|
||||
class AutoLib(MsgBase):
|
||||
@@ -16,7 +16,7 @@ from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.support.ui import WebDriverWait
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
|
||||
from LibOperator import LibOperator
|
||||
from base.LibOperator import LibOperator
|
||||
|
||||
|
||||
class LibChecker(LibOperator):
|
||||
@@ -25,7 +25,7 @@ class LibChecker(LibOperator):
|
||||
self,
|
||||
input_queue: queue.Queue,
|
||||
output_queue: queue.Queue,
|
||||
driver
|
||||
driver: any
|
||||
):
|
||||
|
||||
super().__init__(input_queue, output_queue)
|
||||
@@ -270,11 +270,11 @@ class LibChecker(LibOperator):
|
||||
|
||||
|
||||
def canCheckin(
|
||||
self,
|
||||
date: str
|
||||
self
|
||||
) -> 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, "已预约")
|
||||
if record is not None:
|
||||
begin_time = record["time"]["begin"]
|
||||
@@ -307,11 +307,11 @@ class LibChecker(LibOperator):
|
||||
|
||||
|
||||
def canRenew(
|
||||
self,
|
||||
date: str
|
||||
) -> bool:
|
||||
self
|
||||
):
|
||||
|
||||
# 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, "使用中")
|
||||
if record is not None:
|
||||
end_time = record["time"]["end"]
|
||||
@@ -325,9 +325,9 @@ class LibChecker(LibOperator):
|
||||
)
|
||||
if abs(time_diff_seconds) < 120*60:
|
||||
self._showTrace(f"{trace_msg}, 可以续约")
|
||||
return True
|
||||
return record
|
||||
else:
|
||||
self._showTrace(f"{trace_msg}, 无法续约")
|
||||
return False
|
||||
return None
|
||||
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 import expected_conditions as EC
|
||||
|
||||
from LibOperator import LibOperator
|
||||
from base.LibOperator import LibOperator
|
||||
|
||||
|
||||
class LibCheckin(LibOperator):
|
||||
@@ -25,7 +25,7 @@ class LibCheckin(LibOperator):
|
||||
self,
|
||||
input_queue: queue.Queue,
|
||||
output_queue: queue.Queue,
|
||||
driver
|
||||
driver: any
|
||||
):
|
||||
|
||||
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 import expected_conditions as EC
|
||||
|
||||
from LibOperator import LibOperator
|
||||
from base.LibOperator import LibOperator
|
||||
|
||||
|
||||
class LibCheckout(LibOperator):
|
||||
@@ -25,7 +25,7 @@ class LibCheckout(LibOperator):
|
||||
self,
|
||||
input_queue: queue.Queue,
|
||||
output_queue: queue.Queue,
|
||||
driver
|
||||
driver: any
|
||||
):
|
||||
|
||||
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 import expected_conditions as EC
|
||||
|
||||
from LibOperator import LibOperator
|
||||
from base.LibOperator import LibOperator
|
||||
|
||||
|
||||
class LibLogin(LibOperator):
|
||||
@@ -26,7 +26,7 @@ class LibLogin(LibOperator):
|
||||
self,
|
||||
input_queue: queue.Queue,
|
||||
output_queue: queue.Queue,
|
||||
driver
|
||||
driver: any
|
||||
):
|
||||
|
||||
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 import expected_conditions as EC
|
||||
|
||||
from LibOperator import LibOperator
|
||||
from base.LibOperator import LibOperator
|
||||
|
||||
|
||||
class LibLogout(LibOperator):
|
||||
@@ -22,7 +22,7 @@ class LibLogout(LibOperator):
|
||||
self,
|
||||
input_queue: queue.Queue,
|
||||
output_queue: queue.Queue,
|
||||
driver
|
||||
driver: any
|
||||
):
|
||||
|
||||
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.
|
||||
"""
|
||||
import os
|
||||
import time
|
||||
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):
|
||||
@@ -19,7 +25,7 @@ class LibRenew(LibOperator):
|
||||
self,
|
||||
input_queue: queue.Queue,
|
||||
output_queue: queue.Queue,
|
||||
driver
|
||||
driver: any
|
||||
):
|
||||
|
||||
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 import expected_conditions as EC
|
||||
|
||||
from LibOperator import LibOperator
|
||||
from base.LibOperator import LibOperator
|
||||
|
||||
|
||||
class LibReserve(LibOperator):
|
||||
@@ -25,7 +25,7 @@ class LibReserve(LibOperator):
|
||||
self,
|
||||
input_queue: queue.Queue,
|
||||
output_queue: queue.Queue,
|
||||
driver
|
||||
driver: any
|
||||
):
|
||||
|
||||
super().__init__(input_queue, output_queue)
|
||||
@@ -324,11 +324,52 @@ class LibReserve(LibOperator):
|
||||
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(
|
||||
self,
|
||||
date_str: str
|
||||
) -> 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(
|
||||
trigger_locator=(By.ID, "onDate_select"),
|
||||
option_locator=(By.XPATH, f"//p[@id='options_onDate']/a[@value='{date_str}']"),
|
||||
@@ -342,12 +383,20 @@ class LibReserve(LibOperator):
|
||||
place: str
|
||||
) -> 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(
|
||||
trigger_locator=(By.ID, "display_building"),
|
||||
option_locator=(By.XPATH, f"//p[@id='options_building']/a[@value='{actual_place}']"),
|
||||
success_msg=f"预约场所 {place} 选择成功 !",
|
||||
fail_msg=f"选择预约场所失败 ! : {place} 不可用"
|
||||
option_locator=(By.XPATH, f"//p[@id='options_building']/a[@value='{place}']"),
|
||||
success_msg=f"预约场所 {display_place} 选择成功 !",
|
||||
fail_msg=f"选择预约场所失败 ! : {display_place} 不可用"
|
||||
)
|
||||
|
||||
|
||||
@@ -357,6 +406,13 @@ class LibReserve(LibOperator):
|
||||
) -> bool:
|
||||
|
||||
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(
|
||||
trigger_locator=(By.ID, "floor_select"),
|
||||
option_locator=(By.XPATH, f"//p[@id='options_floor']/a[@value='{floor}']"),
|
||||
@@ -371,12 +427,24 @@ class LibReserve(LibOperator):
|
||||
) -> bool:
|
||||
|
||||
display_room = self.__room_map.get(room)
|
||||
return self.__clickElement(
|
||||
trigger_locator=(By.ID, f"room_{room}"),
|
||||
option_locator=None,
|
||||
success_msg=f"房间 {display_room} 选择成功 !",
|
||||
fail_msg=f"选择房间失败 ! : {display_room} 不可用"
|
||||
)
|
||||
# find room
|
||||
try:
|
||||
WebDriverWait(self.__driver, 2).until(
|
||||
EC.element_to_be_clickable((By.ID, "findRoom"))
|
||||
).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(
|
||||
@@ -572,22 +640,13 @@ class LibReserve(LibOperator):
|
||||
except:
|
||||
self._showTrace(f"加载预约选座页面失败 !")
|
||||
return False
|
||||
# date, place, floor
|
||||
# date, place, floor, room
|
||||
if not self.__selectDate(reserve_info["date"]):
|
||||
return False
|
||||
if not self.__selectPlace(reserve_info["place"]):
|
||||
return False
|
||||
if not self.__selectFloor(reserve_info["floor"]):
|
||||
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"]):
|
||||
return False
|
||||
else:
|
||||
@@ -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