def fetch_book_detail_from_google(isbn): """Fetch book from Google Book Service and Return dict of book info""" service = BookService() result = service.search(isbn) book_dict = {} matched_book = None for book in result.entry: for identifier in book.identifier: if isbn in identifier.text: matched_book = book break book_dict = matched_book.to_dict() if matched_book: for identifier in matched_book.identifier: """ Book Identifiers: [('google_id', 'dwSfGQAACAAJ'), ('ISBN', '0132350882'), ('ISBN', '9780132350884')] """ if 'ISBN' in identifier.text: isbn = identifier.text.split(':',1)[1] if len(isbn) == 10: book_dict['isbn10'] = isbn elif len(isbn) == 13: book_dict['isbn13'] = isbn return book_dict
def query_book_info(isbn): """Retrieve a book info that matches with the ISBN provided""" def match_isbn(book): """Book Identifiers: (key,val) [('google_id', 'dwSfGQAACAAJ'), ('ISBN', '0132350882'), ('ISBN', '9780132350884')]""" ids = [ids_keyval[1] for ids_keyval in book.get('identifiers', [])] return isbn in ids # GET https://www.googleapis.com/books/v1/volumes?q=isbn:<ISBN> service = BookService() result = service.search('isbn:' + isbn) result_dict = map(lambda entry: entry.to_dict(), result.entry) match_results = filter(match_isbn, result_dict) return match_results[0] if match_results else None
def search_book(query): service = BookService() result = service.search(query) return map(lambda entry: entry.to_dict(), result.entry)
from gdata.books.service import BookService servicio = BookService() busqueda = raw_input('Ingresa el ISBN que quieres buscar:') resultado = servicio.search('ISBN' + busqueda) if resultado.entry: datos = resultado.entry[0].to_dict() print 'Datos del libro:' print 'Titulo:', datos['title'] print 'Tapa:', datos['thumbnail'] print 'Fecha:', datos['date'] print 'Genero:', ', '.join(datos['subjects']) print 'Autores:', ', '.join(datos['authors']) print 'Descripcion:' print datos['description'] else: print 'No encotre ese ISBN :('