Exemple #1
0
def create_book(name, **kwargs):
    owner_id = get_current_user_id()
    if not owner_id:
        return False
    description = kwargs.get('description')
    genres_ids = kwargs.get('genres_ids') or []
    cover_image_url = kwargs.get('cover_image_url')
    page_count = kwargs.get('page_count')
    author_name = kwargs.get('author_name')
    year = kwargs.get('year')

    book = Book(name=name, owner_id=owner_id)
    book.description = description
    book.cover_image_url = cover_image_url
    book.page_count = page_count
    book.author_name = author_name
    book.year = year

    genres = []
    for id in genres_ids:
        g = get_genre_by_id(id)
        if g:
            genres.append(g)
    book.genres = genres

    session.add(book)
    session.commit()
    return book
Exemple #2
0
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