From d898b995622a8ebfc44c0edbb8ead2cfbfb00e8e Mon Sep 17 00:00:00 2001 From: Vishnu KS Date: Mon, 30 Nov 2020 00:15:17 +0530 Subject: [PATCH] Check if Google Books API key is present. --- utils/gooodreads.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/utils/gooodreads.py b/utils/gooodreads.py index 253311e..697b1e7 100644 --- a/utils/gooodreads.py +++ b/utils/gooodreads.py @@ -42,16 +42,17 @@ def get_details(book_object): book_object["description"] = BeautifulSoup(description).text else: book_object["description"] = "" - # Attempt to use Google Book API - url = "https://www.googleapis.com/books/v1/volumes?q={}+inauthor:{}&key={}".format( - book_object["title"], book_object["author"], GOOGLE_BOOK_API_KEY, - ) - response = requests.request("GET", url) + if GOOGLE_BOOK_API_KEY.strip(" "): + # Attempt to use Google Book API + url = "https://www.googleapis.com/books/v1/volumes?q={}+inauthor:{}&key={}".format( + book_object["title"], book_object["author"], GOOGLE_BOOK_API_KEY, + ) + response = requests.request("GET", url) - for item in response.json()["items"]: - if "description" in item["volumeInfo"]: - book_object["description"] = item["volumeInfo"]["description"] - break + for item in response.json()["items"]: + if "description" in item["volumeInfo"]: + book_object["description"] = item["volumeInfo"]["description"] + break print("Fetching amazon link")