From ba97d1ec7fd6550e0afeb37eb747248e42bec65f Mon Sep 17 00:00:00 2001 From: "B. Stack" Date: Fri, 12 Jul 2024 12:49:28 -0400 Subject: aspen: add available reservations --- libraries/aspen.py | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) (limited to 'libraries') diff --git a/libraries/aspen.py b/libraries/aspen.py index 5b678f9..bb430c3 100644 --- a/libraries/aspen.py +++ b/libraries/aspen.py @@ -61,10 +61,15 @@ class Library(BaseLibrary): output = s.get(f"{b}/MyAccount/AJAX",params=params,headers=headers) 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 -- cgit