From 4cde49ddca2f1afa4f5a4e51018aadcd5dcb43f4 Mon Sep 17 00:00:00 2001 From: Avineshwar Pratap Singh Date: Mon, 23 Nov 2020 09:52:16 -0600 Subject: [PATCH] Stronger presence check - Fixes `out-of-range` on a Tuple - Ensures `KeyError` doesn't happen for the faulty key. I would argue if someone the script should be re-written to accommodate this in the first place. --- safaribooks.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/safaribooks.py b/safaribooks.py index 98ca66d..fc4bafa 100755 --- a/safaribooks.py +++ b/safaribooks.py @@ -174,7 +174,7 @@ def book_info(self, info): ("Title", info["title"]), ("Authors", ", ".join(aut["name"] for aut in info["authors"])), ("Identifier", info["identifier"]), ("ISBN", info["isbn"]), ("Publishers", ", ".join(pub["name"] for pub in info["publishers"])), - ("Rights", info["rights"]), + ("Rights", info["rights"] if "rights" in info and info["rights"] else ""), ("Description", description[:500] + "..." if len(description) >= 500 else description), ("Release Date", info["issued"]), ("URL", info["web_url"]) @@ -961,7 +961,7 @@ def create_content_opf(self): escape(self.book_info["description"]), subjects, ", ".join(escape(pub["name"]) for pub in self.book_info["publishers"]), - escape(self.book_info["rights"]) if self.book_info["rights"] else "", + escape(self.book_info["rights"]) if "rights" in self.book_info and self.book_info["rights"] else "", self.book_info["issued"], self.cover, "\n".join(manifest),