Пример #1
0
def not_approved_ebooks():
    book_list = get_ebook_pickles()
    not_approved_book_list = []
    for book in book_list:
        if not book.approved and not book.second_pass:
            not_approved_book_list.append(book)
    return not_approved_book_list
Пример #2
0
def not_approved_ebooks():
    book_list = get_ebook_pickles()
    not_approved_book_list = []
    for book in book_list:
        if not book.approved and not book.second_pass:
            not_approved_book_list.append(book)
    return not_approved_book_list
Пример #3
0
def get_most_read_books():
    """
    Returns the top 5 most read/purchased books
    :return: list
    """
    pickle_files = get_ebook_pickles()
    most_read = sort_most_read_books(pickle_files)
    return most_read[0:5]
Пример #4
0
def get_most_read_books():
    """
    Returns the top 5 most read/purchased books
    :return: list
    """
    pickle_files = get_ebook_pickles()
    most_read = sort_most_read_books(pickle_files)
    return most_read[0:5]
Пример #5
0
def populate_rented_books(user):
    """
    Get a random amount of EBook pickle files and loads them into
    rented_book field of a User object
    :param user:
    :return:
    """
    ebook_pickles = get_ebook_pickles()
    for index in range(0, random.randrange(3, 6)):
        user.rented_books[ebook_pickles[index].isbn] = ebook_pickles[index]
Пример #6
0
def get_top_related_books(user_instance):
    """
    Gets at most 5 books that are similar to the one the reader read before.
    :param user_instance: User
    :return: list
    """
    if not bool(user_instance.rented_books):
        return get_most_read_books()
    else:
        random_book_genre = get_genre_frequency(user_instance)
        similar_books = []
        for book in get_ebook_pickles():
            if book.genre == random_book_genre[random.randrange(0, len(random_book_genre))]:
                if not user_instance.rented_books.has_key(book.isbn):
                    similar_books.append(book)
        if len(similar_books) < 5:
            for book in get_ebook_pickles():
                if book not in similar_books and not user_instance.rented_books.has_key(book.isbn):
                    similar_books.append(book)
        return similar_books[0:5]
Пример #7
0
def get_top_rated_books():
    """
    Returns the top 5 rated books
    :return: list
    """
    pickle_files = get_ebook_pickles()
    approved_books = []
    for book in pickle_files:
        if book.approved:
            approved_books.append(book)
    top_books = sort_top_rated(approved_books)
    return top_books[0:5]
Пример #8
0
def get_top_rated_books():
    """
    Returns the top 5 rated books
    :return: list
    """
    pickle_files = get_ebook_pickles()
    approved_books = []
    for book in pickle_files:
        if book.approved:
            approved_books.append(book)
    top_books = sort_top_rated(approved_books)
    return top_books[0:5]
Пример #9
0
def get_top_related_books(user_instance):
    """
    Gets at most 5 books that are similar to the one the reader read before.
    :param user_instance: User
    :return: list
    """
    if not bool(user_instance.rented_books):
        return get_most_read_books()
    else:
        random_book_genre = get_genre_frequency(user_instance)
        similar_books = []
        for book in get_ebook_pickles():
            if book.genre == random_book_genre[random.randrange(
                    0, len(random_book_genre))]:
                if not user_instance.rented_books.has_key(book.isbn):
                    similar_books.append(book)
        if len(similar_books) < 5:
            for book in get_ebook_pickles():
                if book not in similar_books and not user_instance.rented_books.has_key(
                        book.isbn):
                    similar_books.append(book)
        return similar_books[0:5]
Пример #10
0
def search(query):
    try:
        query = int(query)
        book = load_serialized_ebook(str(query))
        if book is not None:
            return book
        else:
            return {}
    except ValueError:
        books = get_ebook_pickles()
        result_set_tuple = process.extract(
            query=query, choices=[book.title for book in books], limit=5)
        found_book_instance = []
        for title in result_set_tuple:
            for book in books:
                if book.title == title[0]:
                    found_book_instance.append(book)
        return found_book_instance
Пример #11
0
def search(query):
    try:
        query = int(query)
        book = load_serialized_ebook(str(query))
        if book is not None:
            return book
        else:
            return {}
    except ValueError:
        books = get_ebook_pickles()
        result_set_tuple = process.extract(query=query,
                                           choices=[book.title for book in books],
                                           limit=5)
        found_book_instance = []
        for title in result_set_tuple:
            for book in books:
                if book.title == title[0]:
                    found_book_instance.append(book)
        return found_book_instance
Пример #12
0
def catalogue_loader():
    book_dict = {
        "TOP": [],
        "Kids": [],
        "Adventure": [],
        "Education": [],
        "DIY": [],
        "Romance": [],
        "Comedy": [],
        "Fantasy": [],
        "Biography": [],
        "History": [],
        "Magazine": [],
        "Religion": [],
        "Sports": []
    }
    for book in get_ebook_pickles():
        if book.approved:
            book_dict[book.genre].append(book)

    for book in get_top_rated_books():
        book_dict["TOP"].append(book)

    return book_dict
Пример #13
0
def catalogue_loader():
    book_dict = {
        "TOP": [],
        "Kids": [],
        "Adventure": [],
        "Education": [],
        "DIY": [],
        "Romance": [],
        "Comedy": [],
        "Fantasy": [],
        "Biography": [],
        "History": [],
        "Magazine": [],
        "Religion": [],
        "Sports": []
    }
    for book in get_ebook_pickles():
        if book.approved:
            book_dict[book.genre].append(book)

    for book in get_top_rated_books():
        book_dict["TOP"].append(book)

    return book_dict