aboutsummaryrefslogtreecommitdiff
path: root/libraries/aspen.py
diff options
context:
space:
mode:
authorB. Stack <bgstack15@gmail.com>2024-07-12 12:49:28 -0400
committerB. Stack <bgstack15@gmail.com>2024-07-12 12:49:28 -0400
commitba97d1ec7fd6550e0afeb37eb747248e42bec65f (patch)
tree49c2d6d2deba2471a8b0281322e7e61c0c6d351c /libraries/aspen.py
parenthtml table width 100% (diff)
downloadlibrary-info-ba97d1ec7fd6550e0afeb37eb747248e42bec65f.tar.gz
library-info-ba97d1ec7fd6550e0afeb37eb747248e42bec65f.tar.bz2
library-info-ba97d1ec7fd6550e0afeb37eb747248e42bec65f.zip
aspen: add available reservations
Diffstat (limited to 'libraries/aspen.py')
-rw-r--r--libraries/aspen.py38
1 files changed, 34 insertions, 4 deletions
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
bgstack15