diff options
author | B. Stack <bgstack15@gmail.com> | 2024-07-12 12:49:28 -0400 |
---|---|---|
committer | B. Stack <bgstack15@gmail.com> | 2024-07-12 12:49:28 -0400 |
commit | ba97d1ec7fd6550e0afeb37eb747248e42bec65f (patch) | |
tree | 49c2d6d2deba2471a8b0281322e7e61c0c6d351c | |
parent | html table width 100% (diff) | |
download | library-info-ba97d1ec7fd6550e0afeb37eb747248e42bec65f.tar.gz library-info-ba97d1ec7fd6550e0afeb37eb747248e42bec65f.tar.bz2 library-info-ba97d1ec7fd6550e0afeb37eb747248e42bec65f.zip |
aspen: add available reservations
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | libraries/aspen.py | 38 |
3 files changed, 35 insertions, 5 deletions
@@ -1,2 +1,3 @@ __pycache__/ config.py +*.html @@ -75,6 +75,5 @@ plugin-based, so I can write a plugins/aspen.py with some standard format output # Improvements I still need to implement these features. -* add reservations for each library * add library card expiration date * try designing the --output html to save the images to files in ./images/{img50}.{img_format} diff --git a/libraries/aspen.py b/libraries/aspen.py index 5b678f9..bb430c3 100644 --- a/libraries/aspen.py +++ b/libraries/aspen.py @@ -62,9 +62,14 @@ class Library(BaseLibrary): output = json.loads(output.content)["holds"].replace("\xa0"," ") soup = BeautifulSoup(output, "html.parser") try: + availableholds_all = soup.find("label",attrs={"for":"availableHoldSort_all"}).parent.next_sibling.next_sibling + except AttributeError: + # the label will not exist if there are no availableHolds + availableholds_all = None + try: unavailableholds_all = soup.find("label",attrs={"for":"unavailableHoldSort_all"}).parent.next_sibling.next_sibling except AttributeError: - # the label will not exist if there are no unavaiableHolds + # the label will not exist if there are no unavailableHolds unavailableholds_all = None if unavailableholds_all: items = unavailableholds_all.find_all("div",class_=["result"]) @@ -88,13 +93,38 @@ class Library(BaseLibrary): "img": img_b64, "img_type": img_type, } - unavailableReservations.append(obj) - # WORKHERE: availableHolds, might not exist in the DOM. Not implemented yet because I have not yet had any available holds. + unavailableReservations.append(obj) + if availableholds_all: + items = availableholds_all.find_all("div",class_=["result"]) + for i in items: + labels = [j.text for j in i.find_all("div","result-label")] + values = [j.text for j in i.find_all("div","result-value")] + values_dict = dict(map(lambda i,j:(i,j),labels,values)) + title_obj = i.find("a",class_="result-title") + img_href = i.find("img")["src"] + img_b64, img_type = self.get_image(img_href) + if verbose: + #print(f"DEBUG available: item {i}", file=sys.stderr) + print(f"DEBUG available: title {title_obj.text}", file=sys.stderr) + print(f"DEBUG available: values_dict {values_dict}", file=sys.stderr) + obj = { + "patron": self.alias, + "position": values_dict["Position"] if "Position" in values_dict else "", + "status": "ready", + "date_placed": values_dict["Date Placed"], + "format": values_dict["Format"], + "location": values_dict["Pickup Location"], + "title": title_obj.text, + "img_href": img_href, + "img50": img_b64[:50], + "img": img_b64, + "img_type": img_type, + } + availableReservations.append(obj) # Return a single list of objects return availableReservations + unavailableReservations def get_checkouts(self, verbose = False): - # WORKHERE: no example of completed renewals at this time checked_out_objects = [] b = self.baseurl s = self.session |