def add_book(data): # add book to openlibrary.org # Define a Book Object authors = [ common.Author(name=author) for author in data['authors'].split(', ') ] book = common.Book( title=data['title'], authors=authors, publisher=data['publisher'], publish_date=data['year'], pages=data['pages'], ) # Add metadata like ISBN 10 and ISBN 13 isbn = data['isbn'] if is_isbn10(isbn): book.add_id('isbn_10', isbn) elif is_isbn13(isbn): book.add_id('isbn_13', isbn) # Create a new book ol = OpenLibrary() new_book = ol.create_book(book) new_book.add_bookcover(data['cover']) new_book.work.add_subject(data['categories']) new_book.save() return new_book
def _ol_book_from_google_book(google_book): google_book_info = google_book["volumeInfo"] # Extract fields that we expect to always exist title = google_book_info["title"] authors = [ ol_common.Author(name=author_name) for author_name in google_book_info["authors"] ] industry_identifiers = _ol_identifiers_from_google_identifiers( google_book_info["industryIdentifiers"]) # Extract fields that may not exist number_of_pages = google_book_info.get("pageCount") publisher = google_book_info.get("publisher") publish_date = google_book_info.get("publishedDate") cover_url = google_book_info.get("imageLinks", {}).get("thumbnail") return ol_common.Book(title=title, number_of_pages=number_of_pages, identifiers=industry_identifiers, authors=authors, publisher=publisher, publish_date=publish_date, cover=cover_url)
def add_book_via_olclient(book, author_list, bookcover=None): if len(author_list) != 0: # Define a Book Object new_book = common.Book(title=book.get("title"), authors=author_list, publish_date=book.get("date"), language=book.get("language")) # Add metadata like ISBN 10 and ISBN 13 new_book.add_id(u'isbn_10', book.get("isbn10")) new_book.add_id(u'isbn_13', book.get('isbn13')) new_book.add_id(u'oclc', book.get('oclc')) print(new_book) try: newer_book = ol.create_book(new_book) if bookcover: newer_book.add_bookcover(bookcover) except Exception as e: print("Book already exists!") else: print("No authors added. Work " + book.get("title") + " has been skipped.")
def row2book(new_book): # Data of the book title = new_book.get('title', u'') author = new_book.get('author', u'') date = new_book.get('date', u'') # Define a Book Object added_book = common.Book(title=title, authors=[common.Author(name=author)], publisher=u"", publish_date=date) return added_book
def create_book(data): # create an `OL` book instance using title and author. # Needed for `seach_book` # fields we expect to always exist title = data["title"] authors = [ol_common.Author(name=author_name) for author_name in data["authors"]] # Extract fields that may not exist industry_identifiers = None # data.get("isbn") number_of_pages = data.get("pages") publisher = data.get("publisher") publish_date = data.get("year") cover_url = None return ol_common.Book( title=title, number_of_pages=number_of_pages, identifiers=industry_identifiers, authors=authors, publisher=publisher, publish_date=publish_date, cover=cover_url, )
def main(): # Defining an Open Library Object ol = OpenLibrary() # Define a Book Object book = common.Book( title="Warlight: A novel", authors=[common.Author(name="Michael Ondaatje")], publisher="Deckle Edge", publish_date="2018", ) # Add metadata like ISBN 10 and ISBN 13 book.add_id('isbn_10', '0525521194') book.add_id('isbn_13', '978-0525521198') # Create a new book new_book = ol.create_book(book) # Add a book cover for the given book new_book.add_bookcover( 'https://images-na.ssl-images-amazon.com/images/I/51kmM%2BvVRJL._SX337_BO1,204,203,200_.jpg' )
# Change the Python Run Time Path import sys sys.path.insert(0, '../') # Import necessary libraries to use from olclient.openlibrary import OpenLibrary import olclient.common as common # Defining an Open Library Object ol = OpenLibrary() # Define a Book Object book = common.Book(title="Warlight: A novel", authors=[common.Author(name="Michael Ondaatje")], publisher="Deckle Edge", publish_date="2018") # Add metadata like ISBN 10 and ISBN 13 book.add_id('isbn_10', '0525521194') book.add_id('isbn_13', '978-0525521198') # Create a new book new_book = ol.create_book(book) # Add a book cover for the given book new_book.add_bookcover( 'https://images-na.ssl-images-amazon.com/images/I/51kmM%2BvVRJL._SX337_BO1,204,203,200_.jpg' )
#!/usr/local/bin/python from olclient.openlibrary import OpenLibrary import olclient.common as common import requests import xml.etree.ElementTree as ET import sys isbn_13 = str(sys.argv[1]) API_KEY = '' r = requests.get("https://www.goodreads.com/search.xml?key=%sq=%s" % (API_KEY, isbn_13)) root = ET.fromstring(r.content) #Parsing XML response from Goodreads title = (root[1][6][0][8][1]).text #Deeply attributed title of the book author = (root[1][6][0][8][2][1]).text #author name image_url = (root[1][6][0][8][3]).text ol = OpenLibrary() book = common.Book(title=title, authors=[common.Author(name=author)]) book.add_id(u'isbn_13', isbn_13) new_book = ol.create_book(book) new_book.add_bookcover(image_url)