From e55ef2d33e26b9c849514a04a0576f732375daf7 Mon Sep 17 00:00:00 2001 From: WorldTeacher <41587052+WorldTeacher@users.noreply.github.com> Date: Tue, 29 Oct 2024 13:02:20 +0100 Subject: [PATCH] add use_any function enable the addition of any matching book even if the book is not currently in the semesterapparat --- src/logic/webrequest.py | 58 +++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/src/logic/webrequest.py b/src/logic/webrequest.py index 6f22c3f..ee04a99 100644 --- a/src/logic/webrequest.py +++ b/src/logic/webrequest.py @@ -34,13 +34,16 @@ class WebRequest: def __init__(self) -> None: """Request data from the web, and format it depending on the mode.""" self.apparat = None - + self.use_any = False # use any book that matches the search term self.signature = None self.ppn = None self.data = None self.timeout = 5 logger.log_info("Initialized WebRequest") - + + def use_any_book(self): + self.use_any = True + return self def set_apparat(self, apparat): self.apparat = apparat if int(self.apparat) < 10: @@ -91,6 +94,17 @@ class WebRequest: item_location = location.find( "div", class_="col-xs-12 col-md-7 col-lg-8 rds-dl-panel" ).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
 tag found")
+                            return return_data
                     if f"Semesterapparat-{self.apparat}" in item_location:
                         pre_tag = soup.find_all("pre")
                         return_data = []
@@ -112,7 +126,7 @@ class WebRequest:
             soup = BeautifulSoup(result, "html.parser")
             locations = soup.find_all("div", class_="col-xs-12 rds-dl RDS_LOCATION")
             if locations:
-                for location in locations:
+                for _ in locations:
                     pre_tag = soup.find_all("pre")
                     return_data = []
                     if pre_tag:
@@ -130,9 +144,6 @@ class BibTextTransformer:
         Valid Modes are ARRAY, COinS, BibTeX, RIS, RDS
     Raises:
         ValueError: Raised if mode is not in valid_modes
-
-    Returns:
-        None
     """
 
     valid_modes = ["ARRAY", "COinS", "BibTeX", "RIS", "RDS"]
@@ -190,16 +201,31 @@ class BibTextTransformer:
         """
         if self.data is 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)
+        match self.mode:
+            case "ARRAY":
+                return ARRAYData().transform(self.data)
+            case "COinS":
+                return COinSData().transform(self.data)
+            case "BibTeX":
+                return BibTeXData().transform(self.data)
+            case "RIS":
+                return RISData().transform(self.data)
+            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):