From 8cf45c24325f419412da19743ecbc5e26fe511b5 Mon Sep 17 00:00:00 2001 From: jesopo Date: Sun, 22 Jul 2018 20:53:44 +0100 Subject: [PATCH] rating, date and authors are optional in google's book apis --- modules/books.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/modules/books.py b/modules/books.py index 1d9c9f4c..cc151888 100644 --- a/modules/books.py +++ b/modules/books.py @@ -26,12 +26,19 @@ class Module(object): title = book["title"] sub_title = (", %s" % book.get("subtitle") ) if book.get("subtitle") else "" - authors = ", ".join(book["authors"]) - date = book["publishedDate"] - rating = book["averageRating"] + + authors = ", ".join(book.get("authors", [])) + authors = " - %s" % authors if authors else "" + + date = book.get("publishedDate", "") + date = " (%s)" % date if date else "" + + rating = book.get("averageRating", -1) + rating = " (%s/5.0)" % rating if not rating == -1 else "" + id = re.search(REGEX_BOOKID, book["infoLink"]).group(1) - info_link = URL_BOOKINFO % id - event["stdout"].write("%s - %s (%s)%s %s (%s/5.0)" % ( + info_link = " %s" % (URL_BOOKINFO % id) + event["stdout"].write("%s%s%s%s%s%s" % ( title, authors, date, sub_title, info_link, rating)) else: event["stderr"].write("Unable to find book")