Skip to content

Commit

Permalink
SB237: Replace dictionary lookup with get method with default value.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ai Tran committed Nov 20, 2020
1 parent 9385e5a commit fef3b21
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions safaribooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,13 @@ def parse_description(self, desc):
def book_info(self, info):
description = self.parse_description(info["description"]).replace("\n", " ")
for t in [
("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"])),
("Title", info.get("title", "")), ("Authors", ", ".join(aut["name"] for aut in info.get("authors", ""))),
("Identifier", info.get("identifier", "")), ("ISBN", info.get("isbn", "")),
("Publishers", ", ".join(pub["name"] for pub in info.get("publishers", ""))),
("Rights", info.get("rights", "")),
("Description", description[:500] + "..." if len(description) >= 500 else description),
("Release Date", info["issued"]),
("URL", info["web_url"])
("Release Date", info.get("issued", "")),
("URL", info.get("web_url", ""))
]:
self.info("{0}{1}{2}: {3}".format(self.SH_YELLOW, t[0], self.SH_DEFAULT, t[1]), True)

Expand Down Expand Up @@ -955,14 +955,14 @@ def create_content_opf(self):
for sub in self.book_info["subjects"])

return self.CONTENT_OPF.format(
(self.book_info["isbn"] if self.book_info["isbn"] else self.book_id),
(self.book_info.get("isbn", self.book_id)),
escape(self.book_title),
authors,
escape(self.book_info["description"]),
escape(self.book_info.get("description", "")),
subjects,
", ".join(escape(pub["name"]) for pub in self.book_info["publishers"]),
", ".join(escape(pub["name"]) for pub in self.book_info.get("publishers", "")),
escape(self.book_info.get("rights", "")),
self.book_info["issued"],
self.book_info.get("issued", ""),
self.cover,
"\n".join(manifest),
"\n".join(spine),
Expand Down

0 comments on commit fef3b21

Please sign in to comment.