add use_any function

enable the addition of any matching book even if the book is not currently in the semesterapparat
This commit is contained in:
WorldTeacher
2024-10-29 13:02:20 +01:00
parent 60106a421b
commit e55ef2d33e

View File

@@ -34,13 +34,16 @@ class WebRequest:
def __init__(self) -> None: def __init__(self) -> None:
"""Request data from the web, and format it depending on the mode.""" """Request data from the web, and format it depending on the mode."""
self.apparat = None self.apparat = None
self.use_any = False # use any book that matches the search term
self.signature = None self.signature = None
self.ppn = None self.ppn = None
self.data = None self.data = None
self.timeout = 5 self.timeout = 5
logger.log_info("Initialized WebRequest") logger.log_info("Initialized WebRequest")
def use_any_book(self):
self.use_any = True
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:
@@ -91,6 +94,17 @@ class WebRequest:
item_location = location.find( item_location = location.find(
"div", class_="col-xs-12 col-md-7 col-lg-8 rds-dl-panel" "div", class_="col-xs-12 col-md-7 col-lg-8 rds-dl-panel"
).text.strip() ).text.strip()
if self.use_any:
pre_tag = soup.find_all("pre")
return_data = []
if pre_tag:
for tag in pre_tag:
data = tag.text.strip()
return_data.append(data)
return return_data
else:
logger.log_error("No <pre> tag found")
return return_data
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 = []
@@ -112,7 +126,7 @@ class WebRequest:
soup = BeautifulSoup(result, "html.parser") soup = BeautifulSoup(result, "html.parser")
locations = soup.find_all("div", class_="col-xs-12 rds-dl RDS_LOCATION") locations = soup.find_all("div", class_="col-xs-12 rds-dl RDS_LOCATION")
if locations: if locations:
for location in locations: for _ in locations:
pre_tag = soup.find_all("pre") pre_tag = soup.find_all("pre")
return_data = [] return_data = []
if pre_tag: if pre_tag:
@@ -130,9 +144,6 @@ class BibTextTransformer:
Valid Modes are ARRAY, COinS, BibTeX, RIS, RDS Valid Modes are ARRAY, COinS, BibTeX, RIS, RDS
Raises: Raises:
ValueError: Raised if mode is not in valid_modes ValueError: Raised if mode is not in valid_modes
Returns:
None
""" """
valid_modes = ["ARRAY", "COinS", "BibTeX", "RIS", "RDS"] valid_modes = ["ARRAY", "COinS", "BibTeX", "RIS", "RDS"]
@@ -190,16 +201,31 @@ class BibTextTransformer:
""" """
if self.data is None: if self.data is None:
return None return None
if self.mode == "ARRAY": match self.mode:
return ARRAYData().transform(self.data) case "ARRAY":
elif self.mode == "COinS": return ARRAYData().transform(self.data)
return COinSData().transform(self.data) case "COinS":
elif self.mode == "BibTeX": return COinSData().transform(self.data)
return BibTeXData().transform(self.data) case "BibTeX":
elif self.mode == "RIS": return BibTeXData().transform(self.data)
return RISData().transform(self.data) case "RIS":
elif self.mode == "RDS": return RISData().transform(self.data)
return RDSData().transform(self.data).return_data(option) case "RDS":
return RDSData().transform(self.data).return_data(option)
case None:
return None
# if self.mode == "ARRAY":
# return ARRAYData().transform(self.data)
# elif self.mode == "COinS":
# return COinSData().transform(self.data)
# elif self.mode == "BibTeX":
# return BibTeXData().transform(self.data)
# elif self.mode == "RIS":
# return RISData().transform(self.data)
# elif self.mode == "RDS":
# return RDSData().transform(self.data).return_data(option)
def cover(isbn): def cover(isbn):