diff options
author | B. Stack <bgstack15@gmail.com> | 2024-07-10 23:07:49 -0400 |
---|---|---|
committer | B. Stack <bgstack15@gmail.com> | 2024-07-10 23:07:49 -0400 |
commit | 684b84c78cf65c767ffcf077ed7f89106a1acf26 (patch) | |
tree | 7a6a256f76ef239f5374d63ed5e43ac1e1eefd13 | |
parent | prepare for reservations (diff) | |
download | library-info-684b84c78cf65c767ffcf077ed7f89106a1acf26.tar.gz library-info-684b84c78cf65c767ffcf077ed7f89106a1acf26.tar.bz2 library-info-684b84c78cf65c767ffcf077ed7f89106a1acf26.zip |
use reservations in all get_ calls
-rw-r--r-- | libraries/aspen.py | 13 | ||||
-rw-r--r-- | libraries/base.py | 13 | ||||
-rw-r--r-- | libraries/polaris.py | 8 | ||||
-rwxr-xr-x | library_info_cli.py | 37 | ||||
-rw-r--r-- | 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"</table>\n") else: prn(f"No checkouts.\n") + 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("<tbody>\n") + for i in reservations: + prn(f"<tr>") + prn(f"<td>{i['date_placed']}</td>") + prn(f"<td>{i['location']}</td>") + prn(f"<td>{i['position']}</td>") + prn(f"<td>{i['status']}</td>") + if "img" in i: + img_src = i["img"] + else: + img_src = "" + prn(f"<td><img class='thumb' src='data:{i['img_type']};base64, {img_src}' /></td>") + prn(f"<td>{i['title']}</td>") + prn(f"</tr>\n") + prn(f"</tbody>\n") + prn(f"</table>\n") + else: + prn("No reservations.\n") prn(f"</body>\n") prn(f"<footer>\n") prn(f"</footer>\n") @@ -124,8 +146,10 @@ def html(checkouts): prn(""" <script>$(document).ready( function () { - var table = $('#checkouts').DataTable({paging: false}); - table.column('2:visible').order('asc').draw(); + var table1 = $('#checkouts').DataTable({paging: false}); + table1.column('2:visible').order('asc').draw(); + var table2 = $('#reservations').DataTable({paging: false}); + table2.column('0:visible').order('desc').draw(); } );</script> """) @@ -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 = [] |