diff options
Diffstat (limited to 'library_info_cli.py')
-rwxr-xr-x | library_info_cli.py | 26 |
1 files changed, 20 insertions, 6 deletions
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 "<td><img class='thumb' src='data:{i['img_type']};base64, {img_src}' /></td>" + return f"<td><img class='thumb' src='data:{i['img_type']};base64, {img_src}' /></td>" else: # No image available. This might happen? return "<td>none</td>" # failsafe return "<td>none</td>" -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"</table>\n") else: prn("No reservations.\n") + prn(f"<h2>Card expiration dates</h2>\n") + prn(f"<table>\n") + prn(f"<tr><th>Patron</th><th>date</th></tr>\n") + for i in card_expiration_dates: + expires = i["expires"].strftime("%F") + prn(f"<tr><td>{i['patron']}</td><td>{expires}</td>\n") + prn(f"</table>\n") prn(f"</body>\n") prn(f"<footer>\n") prn(f"</footer>\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}.") |