From 113f68d455f56a6c5b29f8870131cd44d1192812 Mon Sep 17 00:00:00 2001 From: "B. Stack" Date: Wed, 31 Jul 2024 08:46:01 -0400 Subject: adjust aspen reservations again --- libraries/aspen.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'libraries') diff --git a/libraries/aspen.py b/libraries/aspen.py index f37fad7..4b84178 100644 --- a/libraries/aspen.py +++ b/libraries/aspen.py @@ -60,6 +60,8 @@ class Library(BaseLibrary): } output = s.get(f"{b}/MyAccount/AJAX",params=params,headers=headers) output = json.loads(output.content)["holds"].replace("\xa0"," ") + #with open(os.path.join("/tmp",self.alias + ".html"),"w") as w: + # w.write(output) soup = BeautifulSoup(output, "html.parser") holds_all = soup.find_all("div",class_=["result"]) for i in holds_all: @@ -73,7 +75,13 @@ class Library(BaseLibrary): pos_values = [j.text for j in pos_obj.find_all("div","result-value")] pos_values_dict = dict(map(lambda pos_obj,j:(pos_obj,j),pos_labels,pos_values)) except Exception as e: - pos_values_dict = {} + try: + pos_obj = i.parent.next_sibling + pos_labels = [j.text for j in pos_obj.find_all("div","result-label")] + pos_values = [j.text for j in pos_obj.find_all("div","result-value")] + pos_values_dict = dict(map(lambda pos_obj,j:(pos_obj,j),pos_labels,pos_values)) + except Exception as e2: + pos_values_dict = {} for p in pos_values_dict: values_dict[p] = pos_values_dict[p] title_obj = i.find("a",class_="result-title") @@ -85,7 +93,6 @@ class Library(BaseLibrary): obj = { "patron": self.alias, "position": values_dict["Position"] if "Position" in values_dict else "", - "status": values_dict["Status"], "format": values_dict["Format"], "location": values_dict["Pickup Location"], "title": title_obj.text, @@ -94,10 +101,16 @@ class Library(BaseLibrary): "img": img_b64, "img_type": img_type, } - if "Date Placed" in values_dict: + if "Pickup By" in values_dict: + obj["date_placed"] = "until " + values_dict["Pickup By"] + else: obj["date_placed"] = "placed " + values_dict["Date Placed"] + if "Status" in values_dict: + obj["status"] = values_dict["Status"] else: - obj["date_placed"] = "until " + values_dict["Pickup By"] + obj["status"] = "" + if "Available" in values_dict: + obj["status"] = "Available " + values_dict["Available"] reservations.append(obj) return reservations -- cgit