From 684b84c78cf65c767ffcf077ed7f89106a1acf26 Mon Sep 17 00:00:00 2001 From: "B. Stack" Date: Wed, 10 Jul 2024 23:07:49 -0400 Subject: use reservations in all get_ calls --- libraries/aspen.py | 13 ++++++++----- libraries/base.py | 13 +++++++++++++ libraries/polaris.py | 8 ++++++++ library_info_cli.py | 37 +++++++++++++++++++++++++++++++------ library_info_lib.py | 14 ++++++++++---- 5 files changed, 70 insertions(+), 15 deletions(-) diff --git a/libraries/aspen.py b/libraries/aspen.py index 40e67c1..b024263 100644 --- a/libraries/aspen.py +++ b/libraries/aspen.py @@ -54,7 +54,11 @@ class Library(BaseLibrary): "Referer": f"{b}/MyAccount/CheckedOut?source=all" } s.get(f"{b}/Holds?source=ils",headers=headers) - output = s.get(f"{b}/AJAX?method=getHolds&source=all",headers=headers) + params = { + "method": "getHolds", + "source": "all" + } + 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: @@ -65,8 +69,8 @@ class Library(BaseLibrary): if unavailableholds_all: items = unavailableholds_all.find_all("div",class_=["result"]) for i in items: - labels = [j.text for i in i.find_all("div","result-label")] - values = [j.text for i in i.find_all("div","result-value")] + 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"] @@ -84,13 +88,12 @@ class Library(BaseLibrary): "img_type": img_type, } unavailableReservations.append(obj) - # WORKHERE: availableHolds, might not be available. # Return a single list of objects return availableReservations + unavailableReservations def get_checkouts(self, verbose = False): - # WORKHERE: no example of possible/completed renewals at this time + # WORKHERE: no example of completed renewals at this time checked_out_objects = [] b = self.baseurl s = self.session diff --git a/libraries/base.py b/libraries/base.py index f6f75e4..3c68616 100644 --- a/libraries/base.py +++ b/libraries/base.py @@ -26,6 +26,19 @@ class BaseLibrary: self.baseurl = baseurl # will need cookies or session manager here. + def get_reservations(self, verbose = False): + sample = { + "position": "1", + "status": "pending", + "date_placed": "2024-07-11", + "format": "DVD", + "location": "Somewhere", + "title": "Example reserved dvd", + "img": "DUMMYIMAGE23412341234", + "img_type": "image/sample", + } + return [sample] + def get_checkouts(self): """ STUB """ sample = { diff --git a/libraries/polaris.py b/libraries/polaris.py index a47a289..c2edf9c 100644 --- a/libraries/polaris.py +++ b/libraries/polaris.py @@ -54,6 +54,14 @@ class Library(BaseLibrary): # log in now. Why would we not? self.login() + def get_reservations(self, verbose = False): + """ STUB """ + return [] + #availableReservations = [] + #unavailableReservations = [] + #b = self.baseurl + #s = self.session + def get_checkouts(self, verbose=False): checked_out_objects = [] b = self.baseurl diff --git a/library_info_cli.py b/library_info_cli.py index b77e9f4..7dfd640 100755 --- a/library_info_cli.py +++ b/library_info_cli.py @@ -61,7 +61,7 @@ def serialize(item): eprint(f"WARNING: unknown type {type(item)} for json-serializing object {item}") return item -def html(checkouts): +def html(checkouts, reservations): # Uses https://datatables.net/download/builder?dt/jq-3.7.0/dt-2.0.8/cr-2.0.3/fh-4.0.1 # with css corrected by having the utf-8 line at the top of the .min.css file. """ Make an html of the items """ @@ -115,6 +115,28 @@ def html(checkouts): prn(f"\n") else: prn(f"No checkouts.\n") + prn("

Reservations

\n") + if len(reservations): + prn(f"\n") + prn(f"\n") + prn("\n") + for i in reservations: + prn(f"") + prn(f"") + prn(f"") + prn(f"") + prn(f"") + if "img" in i: + img_src = i["img"] + else: + img_src = "" + prn(f"") + prn(f"") + prn(f"\n") + prn(f"\n") + prn(f"
Date placedlocationpositionstatuscovertitle
{i['date_placed']}{i['location']}{i['position']}{i['status']}{i['title']}
\n") + else: + prn("No reservations.\n") prn(f"\n") prn(f"\n") @@ -124,8 +146,10 @@ def html(checkouts): prn(""" """) @@ -135,14 +159,15 @@ if "__main__" == __name__: if debuglevel >= 1: eprint(args) if single: - checkouts = library_info_lib.get_single_checkouts(alias = single, full_images = full_images, verbose = debuglevel >= 5) + checkouts, reservations = library_info_lib.get_single_configitem(alias = single, full_images = full_images, verbose = debuglevel >= 5) else: - checkouts = library_info_lib.get_all_checkouts(full_images = full_images, verbose = debuglevel >= 5) + checkouts, reservations = library_info_lib.get_all_configitems(full_images = full_images, verbose = debuglevel >= 5) if "raw" == output: print(checkouts) + print(reservations) elif "json" == output: print(json.dumps(checkouts,default=serialize)) elif "html" == output: - html(checkouts) + html(checkouts, reservations) else: print(f"Error! Invalid choice for output format {output}.") diff --git a/library_info_lib.py b/library_info_lib.py index 202ec71..ae724ae 100644 --- a/library_info_lib.py +++ b/library_info_lib.py @@ -17,19 +17,23 @@ import sys, os import libraries from config import config -def get_all_checkouts(full_images = True, verbose = False): +def get_all_configitems(full_images = True, verbose = False): # get all checked out items checkouts = [] + reservations = [] for i in config: #print(f"Found config entry {i}") instance = i["class"](i) checkouts += instance.get_checkouts(verbose = verbose) + reservations += instance.get_reservations(verbose=verbose) if not full_images: checkouts = trim_full_images(checkouts) - return checkouts + reservations = trim_full_images(reservations) + return checkouts, reservations -def get_single_checkouts(alias = None, full_images = True, verbose = False): +def get_single_configitem(alias = None, full_images = True, verbose = False): checkouts = [] + reservations = [] this_config = [i for i in config if i["alias"] == alias] if not this_config: raise Exception(f"Alias not found: {alias}") @@ -37,9 +41,11 @@ def get_single_checkouts(alias = None, full_images = True, verbose = False): for i in this_config: instance = i["class"](i) checkouts += instance.get_checkouts(verbose=verbose) + reservations += instance.get_reservations(verbose=verbose) if not full_images: checkouts = trim_full_images(checkouts) - return checkouts + reservations = trim_full_images(reservations) + return checkouts, reservations def trim_full_images(checkouts = []): output = [] -- cgit