From f813486db8c60d9659c99896c8ab49039d489256 Mon Sep 17 00:00:00 2001 From: "B. Stack" Date: Sat, 13 Jul 2024 16:39:56 -0400 Subject: output the card expiration dates --- library_info_cli.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'library_info_cli.py') diff --git a/library_info_cli.py b/library_info_cli.py index cf80043..2362c85 100755 --- a/library_info_cli.py +++ b/library_info_cli.py @@ -56,14 +56,14 @@ def html_td_img(i, imagepath, imagerelativepath): else: # Just print it inline in the html. img_src = i["img"] - return "" + return f"" else: # No image available. This might happen? return "none" # failsafe return "none" -def html(checkouts, reservations, imagepath, imagerelativepath): +def html(checkouts, reservations, imagepath, imagerelativepath, card_expiration_dates): # WORKHERE: need to revise this to take a list of config entries to load, so we can collect card expiration info """ Make a pretty html page of the items. If imagepath and imagerelativepath are defined, save the images to imagepath, and set the html img tags src attribute to the imagerelativepath. @@ -135,6 +135,13 @@ def html(checkouts, reservations, imagepath, imagerelativepath): prn(f"\n") else: prn("No reservations.\n") + prn(f"

Card expiration dates

\n") + prn(f"\n") + prn(f"\n") + for i in card_expiration_dates: + expires = i["expires"].strftime("%F") + prn(f"\n") + prn(f"
Patrondate
{i['patron']}{expires}
\n") prn(f"\n") prn(f"\n") @@ -200,16 +207,23 @@ if imagerelativepath is not None and imagepath is None: if "__main__" == __name__: if debuglevel >= 1: eprint(args) + card_expiration_dates = [] # will hold objects of {"alias": "aspen 1", "expires": datetime.date(2022,11,4)} if single: - checkouts, reservations = library_info_lib.get_single_configitem(alias = single, full_images = full_images, verbose = debuglevel >= 5) + checkouts, reservations, card_expiration_dates = library_info_lib.get_single_configitem(alias = single, full_images = full_images, verbose = debuglevel >= 5) else: - checkouts, reservations = library_info_lib.get_all_configitems(full_images = full_images, verbose = debuglevel >= 5) + checkouts, reservations, card_expiration_dates = library_info_lib.get_all_configitems(full_images = full_images, verbose = debuglevel >= 5) if "raw" == output: print(checkouts) print(reservations) + print(card_expiration_dates) elif "json" == output: - print(json.dumps(checkouts,default=serialize)) + output_json = { + "checkouts": checkouts, + "reservations": reservations, + "card_expiration_dates": card_expiration_dates, + } + print(json.dumps(output_json,default=serialize)) elif "html" == output: - html(checkouts, reservations, imagepath, imagerelativepath) + html(checkouts, reservations, imagepath, imagerelativepath, card_expiration_dates) else: print(f"Error! Invalid choice for output format {output}.") -- cgit