def addRecord(data): """ The incoming 'data' paramater should be a tuple of two dictionaries in the following format: ("author":{"first_name":"John", "last_name":"Doe"}, "book":{"title":"Some book", "isbn":"1234567890", "publisher":"Packt"} ) """ # Create an instance of the Book and Person classes and populate them with the values # collected from the 'Add' dialog and passed in as the tuple of dictionaries. book = Book() book.title = data['book']['title'] book.isbn = data['book']['isbn'] book.publisher = data['book']['publisher'] author = Person() author.first_name = data['author']['first_name'] author.last_name = data['author']['last_name'] book.person = author # Create a session, connect to the database, commit and close the connection. session = connectToDatabase() session.add(book) session.commit() session.close
def add_record(session, data): book = Book() book.title = data["book"]["title"] book.isbn = data["book"]["isbn"] book.publisher = data["book"]["publisher"] author = Person() author.first_name = data["author"]["first_name"] author.last_name = data["author"]["last_name"] book.person = author # try: session.add(book) session.commit()
def add_record(session, data): """ Data should be a dictionary of two dictionaries in the following format: {"author":{"first_name":"John", "last_name":"Doe"}, "book":{"title":"Some book", "isbn":"1234567890", "publisher":"Packt"} } """ book = Book() book.title = data["book"]["title"] book.isbn = data["book"]["isbn"] book.publisher = data["book"]["publisher"] author = Person() author.first_name = data["author"]["first_name"] author.last_name = data["author"]["last_name"] book.person = author session.add(book) session.commit()
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
def addRecord(data): """ Data should be a tuple of two dictionaries in the following format: ("author":{"first_name":"John", "last_name":"Doe"}, "book":{"title":"Some book", "isbn":"1234567890", "publisher":"Packt"} ) """ book = Book() book.title = data["book"]["title"] book.isbn = data["book"]["isbn"] book.publisher = data["book"]["publisher"] author = Person() author.first_name = data["author"]["first_name"] author.last_name = data["author"]["last_name"] book.person = author # connect to session and commit data to database session = connectToDatabase() session.add(book) session.commit() session.close()