feat: implement WebADIS authentication and add medianumber retrieval functionality

This commit is contained in:
2025-10-21 15:26:20 +02:00
parent 0764a6b06a
commit f63bcc8446
12 changed files with 323 additions and 9 deletions

View File

@@ -280,6 +280,21 @@ class Database:
conn.commit()
self.close_connection(conn)
def getWebADISAuth(self) -> Tuple[str, str]:
"""
Get the WebADIS authentication data from the database
Returns:
Tuple[str, str]: The username and password for WebADIS
"""
result = self.query_db(
"SELECT username, password FROM webadis_login WHERE effective_range='SAP'",
one=True,
)
if result is None:
return ("", "")
return (result[0], result[1])
@log.catch
def query_db(
self,

View File

@@ -0,0 +1,10 @@
BEGIN TRANSACTION;
CREATE TABLE IF NOT EXISTS webadis_login (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
username TEXT NOT NULL,
password TEXT NOT NULL
);
COMMIT;

View File

@@ -0,0 +1,6 @@
BEGIN TRANSACTION;
ALTER TABLE webadis_login
ADD COLUMN effective_range TEXT;
COMMIT;

View File

@@ -3,7 +3,8 @@ from PySide6.QtCore import QThread
from PySide6.QtCore import Signal as Signal
from src.backend.database import Database
from src.logic.webrequest import BibTextTransformer, WebRequest
from src.backend.webadis import get_book_medianr
from src.logic.webrequest import BibTextTransformer, TransformerType, WebRequest
from src.shared.logging import log
@@ -37,7 +38,7 @@ class AvailChecker(QThread):
)
# Pre-create reusable request and transformer to avoid per-item overhead
self._request = WebRequest().set_apparat(self.appnumber)
self._rds_transformer = BibTextTransformer("RDS")
self._rds_transformer = BibTextTransformer(TransformerType.RDS)
def run(self):
self.db = Database()
@@ -65,6 +66,12 @@ class AvailChecker(QThread):
break
log.info(f"State of {link}: " + str(state))
# #print("Updating availability of " + str(book_id) + " to " + str(state))
# use get_book_medianr to update the medianr of the book in the database
auth = self.db.getWebADISAuth
medianr = get_book_medianr(rds.items[0].callnumber, self.appnumber, auth)
book_data = book["bookdata"]
book_data.medianr = medianr
self.db.updateBookdata(book["id"], book_data)
self.db.setAvailability(book_id, state)
count += 1
self.updateProgress.emit(count, len(self.links))

35
src/backend/webadis.py Normal file
View File

@@ -0,0 +1,35 @@
from playwright.sync_api import sync_playwright
def get_book_medianr(signature: str, semesterapparat_nr: int, auth: tuple) -> str:
with sync_playwright() as playwright:
browser = playwright.chromium.launch(headless=True)
context = browser.new_context()
page = context.new_page()
page.goto(
"https://bsz.ibs-bw.de:22998/aDISWeb/app?service=direct/0/Home/$DirectLink&sp=SDAP42"
)
page.get_by_role("textbox", name="Benutzer").fill(auth[0])
page.get_by_role("textbox", name="Benutzer").press("Tab")
page.get_by_role("textbox", name="Kennwort").fill(auth[1])
page.get_by_role("textbox", name="Kennwort").press("Enter")
page.get_by_role("button", name="Katalog").click()
page.get_by_role("textbox", name="Signatur").click()
page.get_by_role("textbox", name="Signatur").fill(signature)
page.get_by_role("textbox", name="Signatur").press("Enter")
book_list = page.locator("iframe").content_frame.get_by_role(
"cell", name="Bibliothek der Pädagogischen"
)
# this will always find one result, we need to split the resulting text based on the entries that start with "* "
book_entries = book_list.inner_text().split("\n")
books = []
for entry in book_entries:
if entry.startswith("* "):
books.append(entry)
for book in books:
if f"Semesterapparat: {semesterapparat_nr}" in book:
return book.split("* ")[1].split(":")[0]
# ---------------------
context.close()
browser.close()