aboutsummaryrefslogtreecommitdiff
path: root/libraries
diff options
context:
space:
mode:
authorB. Stack <bgstack15@gmail.com>2024-07-11 09:27:54 -0400
committerB. Stack <bgstack15@gmail.com>2024-07-11 09:27:54 -0400
commit608df68967a78bd9fce89a8497a96dd782b38623 (patch)
treeec295ed0283a20b2443be9e5b1a3f2851d9bd5f5 /libraries
parentuse reservations in all get_ calls (diff)
downloadlibrary-info-608df68967a78bd9fce89a8497a96dd782b38623.tar.gz
library-info-608df68967a78bd9fce89a8497a96dd782b38623.tar.bz2
library-info-608df68967a78bd9fce89a8497a96dd782b38623.zip
implement reservations for polaris
Diffstat (limited to 'libraries')
-rw-r--r--libraries/aspen.py5
-rw-r--r--libraries/polaris.py48
2 files changed, 43 insertions, 10 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("&nbsp;","")
soup2 = BeautifulSoup(details_response,"html.parser")
#details_labels = [i.text for i in soup2.find_all("td",class_="nsm-label") if i.text]
bgstack15