aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libraries/aspen.py5
-rw-r--r--libraries/polaris.py48
-rwxr-xr-xlibrary_info_cli.py3
3 files changed, 45 insertions, 11 deletions
diff --git a/libraries/aspen.py b/libraries/aspen.py
index b024263..5b678f9 100644
--- a/libraries/aspen.py
+++ b/libraries/aspen.py
@@ -76,7 +76,8 @@ class Library(BaseLibrary):
img_href = i.find("img")["src"]
img_b64, img_type = self.get_image(img_href)
obj = {
- "position": values_dict["Position"],
+ "patron": self.alias,
+ "position": values_dict["Position"] if "Position" in values_dict else "",
"status": values_dict["Status"],
"date_placed": values_dict["Date Placed"],
"format": values_dict["Format"],
@@ -88,7 +89,7 @@ class Library(BaseLibrary):
"img_type": img_type,
}
unavailableReservations.append(obj)
- # WORKHERE: availableHolds, might not be available.
+ # WORKHERE: availableHolds, might not exist in the DOM. Not implemented yet because I have not yet had any available holds.
# Return a single list of objects
return availableReservations + unavailableReservations
diff --git a/libraries/polaris.py b/libraries/polaris.py
index c2edf9c..6fab43d 100644
--- a/libraries/polaris.py
+++ b/libraries/polaris.py
@@ -56,11 +56,45 @@ class Library(BaseLibrary):
def get_reservations(self, verbose = False):
""" STUB """
- return []
- #availableReservations = []
- #unavailableReservations = []
- #b = self.baseurl
- #s = self.session
+ # this one lumps them all together in a list. Use the status field.
+ reservations = []
+ b = self.baseurl
+ s = self.session
+ output = s.get(f"{b}/PatronAccount/requests.aspx",headers={"Referer":f"{b}/PatronAccount/itemsout.aspx"}).content
+ soup = BeautifulSoup(output, "html.parser")
+ all_reservations = soup.find_all("tr",class_=["patron-account__grid-row","patron-account__grid-alternating-row"])
+ for item in all_reservations:
+ images_hrefs = [i["src"] for i in item.find_all("img",attrs={"aria-label":"Cover Image"})]
+ titles = [i.text for i in item.find_all("a",class_="patron-account__grid-link")]
+ labels = [i.text for i in item.find_all("label",class_="label-xs")]
+ #print(f"Labels = {labels}",file=sys.stderr)
+ values = [i.next_sibling.next_sibling for i in item.find_all("label",class_="label-xs")]
+ values2 = []
+ for i in values:
+ try:
+ values2.append(i.text)
+ except:
+ # if status = "Transferred for hold" then the position value will be blank.
+ values2.append("")
+ values_dict = dict(map(lambda i,j:(i,j),labels,values2))
+ dates = [i.text.replace("(as of ","").replace(")","").replace("(","") for i in item.find_all("span",class_="patron-account__holds-date")]
+ formats = [i["title"] for i in item.find_all("img") if "aria-label" not in i.attrs]
+ img_b64, img_type = self.get_image(images_hrefs[0])
+ obj = {
+ "patron": self.alias,
+ "position": values_dict["Hold Request Position"],
+ "status": values_dict["Status"],
+ "date_placed": dates[0],
+ "format": formats[0],
+ "location": values_dict["Pickup Library"],
+ "title": titles[0],
+ "img_href": images_hrefs[0],
+ "img50": img_b64[:50],
+ "img": img_b64,
+ "img_type": img_type,
+ }
+ reservations.append(obj)
+ return reservations
def get_checkouts(self, verbose=False):
checked_out_objects = []
@@ -105,9 +139,7 @@ class Library(BaseLibrary):
x = -1
for i in titles:
x += 1
- img_response = s.get(images_hrefs[x])
- img_b64 = base64.b64encode(img_response.content).decode()
- img_type = img_response.headers["Content-Type"]
+ img_b64, img_type = self.get_image(images_hrefs[x])
details_response = s.get(info_links[x]).content.decode().replace(" ","")
soup2 = BeautifulSoup(details_response,"html.parser")
#details_labels = [i.text for i in soup2.find_all("td",class_="nsm-label") if i.text]
diff --git a/library_info_cli.py b/library_info_cli.py
index 7dfd640..6ffaf21 100755
--- a/library_info_cli.py
+++ b/library_info_cli.py
@@ -118,10 +118,11 @@ def html(checkouts, reservations):
prn("<h2>Reservations</h2>\n")
if len(reservations):
prn(f"<table class='display' id='reservations'>\n")
- prn(f"<thead><tr><th>Date placed</th><th>location</th><th>position</th><th>status</th><th>cover</th><th>title</th></thead>\n")
+ prn(f"<thead><tr><th>Patron</th><th>date placed</th><th>location</th><th>position</th><th>status</th><th>cover</th><th>title</th></thead>\n")
prn("<tbody>\n")
for i in reservations:
prn(f"<tr>")
+ prn(f"<td>{i['patron']}</td>")
prn(f"<td>{i['date_placed']}</td>")
prn(f"<td>{i['location']}</td>")
prn(f"<td>{i['position']}</td>")
bgstack15