feat: enhance WebRequest and BibTextTransformer to support exact signature search and any book mode
This commit is contained in:
@@ -39,13 +39,17 @@ class WebRequest:
|
|||||||
self.timeout = 5
|
self.timeout = 5
|
||||||
logger.log_info("Initialized WebRequest")
|
logger.log_info("Initialized WebRequest")
|
||||||
|
|
||||||
|
@property
|
||||||
def use_any_book(self):
|
def use_any_book(self):
|
||||||
|
"""use any book that matches the search term"""
|
||||||
self.use_any = True
|
self.use_any = True
|
||||||
|
logger.log_info("Using any book")
|
||||||
return self
|
return self
|
||||||
def set_apparat(self, apparat):
|
def set_apparat(self, apparat):
|
||||||
self.apparat = apparat
|
self.apparat = apparat
|
||||||
if int(self.apparat) < 10:
|
if int(self.apparat) < 10:
|
||||||
self.apparat = f"0{self.apparat}"
|
self.apparat = f"0{self.apparat}"
|
||||||
|
logger.log_info(f"Set apparat to {self.apparat}")
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def get_ppn(self, signature):
|
def get_ppn(self, signature):
|
||||||
@@ -102,7 +106,7 @@ class WebRequest:
|
|||||||
return return_data
|
return return_data
|
||||||
else:
|
else:
|
||||||
logger.log_error("No <pre> tag found")
|
logger.log_error("No <pre> tag found")
|
||||||
return return_data
|
raise ValueError("No <pre> tag found")
|
||||||
if f"Semesterapparat-{self.apparat}" in item_location:
|
if f"Semesterapparat-{self.apparat}" in item_location:
|
||||||
pre_tag = soup.find_all("pre")
|
pre_tag = soup.find_all("pre")
|
||||||
return_data = []
|
return_data = []
|
||||||
@@ -149,12 +153,18 @@ class BibTextTransformer:
|
|||||||
def __init__(self, mode: str = "ARRAY") -> None:
|
def __init__(self, mode: str = "ARRAY") -> None:
|
||||||
self.mode = mode
|
self.mode = mode
|
||||||
self.field = None
|
self.field = None
|
||||||
|
self.signature = None
|
||||||
if mode not in self.valid_modes:
|
if mode not in self.valid_modes:
|
||||||
logger.log_error(f"Mode {mode} not valid")
|
logger.log_error(f"Mode {mode} not valid")
|
||||||
raise ValueError(f"Mode {mode} not valid")
|
raise ValueError(f"Mode {mode} not valid")
|
||||||
self.data = None
|
self.data = None
|
||||||
# self.bookdata = BookData(**self.data)
|
# self.bookdata = BookData(**self.data)
|
||||||
|
|
||||||
|
def use_signature(self, signature: str):
|
||||||
|
"""use the exact signature to search for the book"""
|
||||||
|
self.signature = signature
|
||||||
|
return self
|
||||||
|
|
||||||
def get_data(self, data: list):
|
def get_data(self, data: list):
|
||||||
RIS_IDENT = "TY -"
|
RIS_IDENT = "TY -"
|
||||||
ARRAY_IDENT = "[kid]"
|
ARRAY_IDENT = "[kid]"
|
||||||
@@ -201,7 +211,7 @@ class BibTextTransformer:
|
|||||||
return None
|
return None
|
||||||
match self.mode:
|
match self.mode:
|
||||||
case "ARRAY":
|
case "ARRAY":
|
||||||
return ARRAYData().transform(self.data)
|
return ARRAYData(self.signature).transform(self.data)
|
||||||
case "COinS":
|
case "COinS":
|
||||||
return COinSData().transform(self.data)
|
return COinSData().transform(self.data)
|
||||||
case "BibTeX":
|
case "BibTeX":
|
||||||
|
|||||||
@@ -12,11 +12,21 @@ class MedienAdder(QtWidgets.QDialog, Ui_Dialog):
|
|||||||
self.color_table()
|
self.color_table()
|
||||||
self.mode = ""
|
self.mode = ""
|
||||||
self.data = []
|
self.data = []
|
||||||
|
self.use_any = False
|
||||||
|
self.use_exact = False
|
||||||
self.lineEdit.returnPressed.connect(self.add_signature)
|
self.lineEdit.returnPressed.connect(self.add_signature)
|
||||||
self.btn_cancel.clicked.connect(self.close)
|
self.btn_cancel.clicked.connect(self.close)
|
||||||
self.btn_save.clicked.connect(self.send_data)
|
self.btn_save.clicked.connect(self.send_data)
|
||||||
#disable button box button okay
|
#disable button box button okay
|
||||||
self.btn_save.setEnabled(False)
|
self.btn_save.setEnabled(False)
|
||||||
|
self.check_use_exact_signature.clicked.connect(self.check_use_exact)
|
||||||
|
self.check_use_any_book.clicked.connect(self.check_use_any)
|
||||||
|
|
||||||
|
def check_use_exact(self):
|
||||||
|
self.use_exact = self.check_use_exact_signature.isChecked()
|
||||||
|
|
||||||
|
def check_use_any(self):
|
||||||
|
self.use_any = self.check_use_any_book.isChecked()
|
||||||
|
|
||||||
def enable_button(self):
|
def enable_button(self):
|
||||||
if self.listWidget.count() > 0:
|
if self.listWidget.count() > 0:
|
||||||
@@ -59,7 +69,7 @@ class MedienAdder(QtWidgets.QDialog, Ui_Dialog):
|
|||||||
item.setText(item.text().split(".")[0])
|
item.setText(item.text().split(".")[0])
|
||||||
|
|
||||||
|
|
||||||
def lauhc_gui():
|
def launch_gui():
|
||||||
app = QtWidgets.QApplication([])
|
app = QtWidgets.QApplication([])
|
||||||
dialog = MedienAdder()
|
dialog = MedienAdder()
|
||||||
dialog.show()
|
dialog.show()
|
||||||
|
|||||||
Reference in New Issue
Block a user