- Removed unnecessary imports from various UI files to streamline the codebase. - Deleted the unused documentation viewer implementation in `documentationview.py`. - Cleaned up imports in `files.py` by removing `LOG_DIR` as it was not used. - Removed the temporary script `temp.py` as it was no longer needed.
94 lines
3.2 KiB
Python
94 lines
3.2 KiB
Python
from typing import List
|
|
|
|
from PySide6 import QtCore
|
|
from PySide6.QtWidgets import QDialog, QPushButton, QVBoxLayout
|
|
from qtqdm import Qtqdm, QtqdmProgressBar
|
|
|
|
from src.core.models import BookData
|
|
from src.services.lehmanns import LehmannsClient
|
|
from src.services.sru import SWB
|
|
|
|
|
|
class CheckThread(QtCore.QThread):
|
|
updateSignal = QtCore.Signal()
|
|
total_entries_signal = QtCore.Signal(int)
|
|
resultSignal = QtCore.Signal(str)
|
|
etaSignal = QtCore.Signal(dict)
|
|
startSignal = QtCore.Signal()
|
|
progress = QtCore.Signal(dict)
|
|
|
|
def __init__(self, items: list[BookData]):
|
|
super().__init__()
|
|
self.items: List[BookData] = items
|
|
self.results: List[tuple[BookData, List[BookData]]] = []
|
|
self.total_entries_signal.emit(len(items))
|
|
|
|
def _update_callback(self, status):
|
|
self.progress.emit(status)
|
|
|
|
def run(self):
|
|
tqdm_object = Qtqdm(
|
|
range(len(self.items)),
|
|
unit_scale=True,
|
|
)
|
|
swb_client = SWB()
|
|
for i in tqdm_object:
|
|
book: BookData = self.items[i]
|
|
author = (
|
|
book.author.split(";")[0].replace(" ", "")
|
|
if ";" in book.author
|
|
else book.author.replace(" ", "")
|
|
)
|
|
# title = book.title.split(":")[0].strip()
|
|
# remove trailing punctuation from title
|
|
title = book.title.rstrip(" .:,;!?")
|
|
response: list[BookData] = []
|
|
response = swb_client.getBooks(
|
|
[
|
|
"pica.bib=20735",
|
|
f"pica.tit={title.split(':')[0].strip()}",
|
|
# f"pica.per={author}",
|
|
]
|
|
)
|
|
|
|
# in the response, remove the entry with the same ppn
|
|
response = [entry for entry in response if entry.ppn != book.ppn]
|
|
for respo in response:
|
|
respo.link = "SWB"
|
|
with LehmannsClient() as client:
|
|
results = client.search_by_title(title, strict=True)
|
|
client.enrich_pages(results)
|
|
if not results:
|
|
continue
|
|
for res in results:
|
|
response.append(BookData().from_LehmannsSearchResult(res))
|
|
if response == []:
|
|
continue
|
|
# check results if lehmanns has a result with the same isbn from the results of swb. if so, if we have a signature, remove, else keep
|
|
response = filter_prefer_swb(response)
|
|
|
|
result = (book, response)
|
|
|
|
self.results.append(result)
|
|
|
|
|
|
class ProgressDialog(QDialog):
|
|
def __init__(self, items: list):
|
|
super().__init__()
|
|
self.setWindowTitle("Progress")
|
|
self.setModal(True)
|
|
layout = QVBoxLayout(self)
|
|
self.progress_bar = QtqdmProgressBar(self)
|
|
self.items: List[BookData] = items
|
|
layout.addWidget(self.progress_bar)
|
|
self.results: List[tuple[BookData, List[BookData]]] = []
|
|
self.start_button = QPushButton("Start Progress", self)
|
|
self.start_button.hide()
|
|
self.start_button.clicked.connect(self.start)
|
|
layout.addWidget(self.start_button)
|
|
|
|
def start(self):
|
|
# Start logic is managed externally; keep method for UI wiring
|
|
pass
|
|
|