diff --git a/src/ui/dialogs/progress.py b/src/ui/dialogs/progress.py new file mode 100644 index 0000000..470a94b --- /dev/null +++ b/src/ui/dialogs/progress.py @@ -0,0 +1,91 @@ +from typing import List, Optional, Set, Union +import re + +from PySide6 import QtCore +from PySide6.QtWidgets import QDialog, QPushButton, QVBoxLayout +from qtqdm import Qtqdm, QtqdmProgressBar + +from src.logic import BookData +from src.logic.lehmannsapi import LehmannsClient +from src.logic.swb 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, + ) + 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().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): + diff --git a/src/ui/widgets/widget_sources/admin_update_signatures.ui b/src/ui/widgets/widget_sources/admin_update_signatures.ui new file mode 100644 index 0000000..9aa3ebf --- /dev/null +++ b/src/ui/widgets/widget_sources/admin_update_signatures.ui @@ -0,0 +1,35 @@ + + + Dialog + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + + Signaturen aktualisieren + + + + + + + 24 + + + + + + + +