import requests url = "https://www.googleapis.com/books/v1/volumes?q=isbn:%s&key=AIzaSyCCYn5v58R08msS06pRfOzTHANUuG2tSHI" % (book.isbn) def get_book_isbn(book): print(book.title) if book.author_name != "Instapaper": url = "https://www.googleapis.com/books/v1/volumes?q=%s+inauthor:%s&key=AIzaSyCCYn5v58R08msS06pRfOzTHANUuG2tSHI" % (book.title, book.author_name) r = requests.get(url, timeout=3.001) data = r.json() isbn10 = "" isbn13 = "" for item in data["items"]: for isbn in item["volumeInfo"]["industryIdentifiers"]: print(isbn['identifier']) if isbn['type'] == "ISBN_13": isbn13 = isbn['identifier'] elif isbn['type'] == "ISBN_10": isbn10 = isbn['identifier'] print(isbn10) return isbn10 break import json def get_book_data(book): if book.author_name != "Instapaper": url = "https://openlibrary.org/api/books?bibkeys=ISBN:%s&format=json&jscmd=data" % book.isbn r = requests.get(url, timeout=9.001) j = json.loads(r.text) obj = "ISBN:%s" % book.isbn try: pages = j[obj]['number_of_pages'] except: pages = '' try: publish_date = j[obj]['publish_date'] except: publish_date = '' try: publish_places = j[obj]['publish_places'][0]['name'] except: publish_places = '' try: openlib_url = j[obj]['url'] except: openlib_url = '' print("pages " + str(pages)) print("date " + publish_date) print("place " + publish_places) print("openlib " + openlib_url) book.pages = pages book.publish_date = publish_date book.publish_place = publish_places book.openlib_url = openlib_url book.save() def fetch_image(book): path = '%s/%s/%s.jpg' %(settings.IMAGES_ROOT, 'book-covers', book.slug) r = requests.get(book.image, timeout=6.001) im = io.StringIO(r.content) # constructs a StringIO holding the image im.save(path)