diff options
| author | 2018-07-22 20:53:44 +0100 | |
|---|---|---|
| committer | 2018-07-22 20:53:44 +0100 | |
| commit | 8cf45c24325f419412da19743ecbc5e26fe511b5 (patch) | |
| tree | 2869fea20e3e0abba9f7839f47517f3ccc0a156b | |
| parent | include quit reasons in print_activity if present (diff) | |
| signature | ||
rating, date and authors are optional in google's book apis
| -rw-r--r-- | modules/books.py | 17 |
1 files 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") |
