def proceed(self, product): # Fetch metadata from Google service = GoogleBookService(utils.configuration.googlebook_key) data = service.fetch_data(product.book.isbn13) if data is not None: # Parse the metadata parser = GoogleBookDataParser() if parser.parse(data): # Convert to book book = Book() book.title = parser.title book.isbn10 = parser.isbn10 book.isbn13 = parser.isbn13 book.year = parser.publishedYear book.description = parser.description book.nb_pages = parser.pageCount book.language = parser.language def convert_name_to_author(name): author = Author() author.name = name return author book.authors = map(convert_name_to_author, parser.authors) if book is not None and book.isbn10 == product.book.isbn10 and book.isbn13 == product.book.isbn13: # Store the book product.book = book # Save data from Googlebook product.metadata_path = "{0}/{1}.json".format(utils.configuration.tmp_path, product.book.isbn13) with open(product.metadata_path, 'w') as outfile: json.dump(data, outfile) # Download the thumbnail product.thumbnail_path = "{0}/{1}.picture".format(utils.configuration.tmp_path, product.book.isbn13) download = Download(parser.thumbnail_url, product.thumbnail_path) downloader = Downloader(download) downloader.run() if download.status: utils.logger.info("Match found in Google Book database [{0}]".format(book.title)) if self.next: return self.next.proceed(product) product.status = Status.Done return product utils.logger.info("This book is unknow from Google Book database") product.status = Status.Error return product
def _load_book_from_worldcat_details_page(html_content, details_page_url, oclc_id): """Given the HTML content of the details page, create a new Book object with all the necessary details.""" current_book = Book() pq_page = pq(html_content) current_book.book_id = oclc_id current_book.title = _load_title_from_worldcat_details_page(pq_page) # TITLE (e.g. 'Lean in : women, work, and the will to lead') current_book.publisher = _load_publisher_from_worldcat_details_page(pq_page) # PUBLISHER (e.g. 'New York : Alfred A. Knopf, 2013.') current_book.worldcaturl = details_page_url current_book.page_count = _load_page_count_from_worldcat_details_page(pq_page) current_book.summary = _load_summary_from_worldcat_details_page(pq_page) current_book.coverurl = _load_cover_url_from_worldcat_details_page(pq_page) # TODO - check if author_name is unique before insertion current_book.authors = _load_authors_from_worldcat_details_page(html_content) isbn10_list, isbn13_list = _load_isbns_from_worldcat_details_page(html_content) current_book.isbn10s = isbn10_list current_book.isbn13s = isbn13_list return current_book