Пример #1
0
def get_genre_frequency(user_instance):
    """
    Takes in an instance of a user object and checks to see
    the frequency of a user's read/purchased history.
    :param user_instance: User Object
    :return: list of genre
    """

    genre_frequency_dict = {
        "Kids": 0,
        "Adventure": 0,
        "Education": 0,
        "DIY": 0,
        "Romance": 0,
        "Comedy": 0,
        "Fantasy": 0,
        "Biography": 0,
        "History": 0,
        "Magazine": 0,
        "Religion": 0,
        "Sports": 0
    }

    genre_list = []

    for key, value in user_instance.rented_books.iteritems():
        genre_frequency_dict[load_serialized_ebook(value.isbn).genre] += 1

    frequency = 0
    for key, value in genre_frequency_dict.iteritems():
        if value >= frequency:
            genre_list.append(key)
            frequency = value
    return genre_list
Пример #2
0
def get_genre_frequency(user_instance):
    """
    Takes in an instance of a user object and checks to see
    the frequency of a user's read/purchased history.
    :param user_instance: User Object
    :return: list of genre
    """

    genre_frequency_dict = {
        "Kids": 0,
        "Adventure": 0,
        "Education": 0,
        "DIY": 0,
        "Romance": 0,
        "Comedy": 0,
        "Fantasy": 0,
        "Biography": 0,
        "History": 0,
        "Magazine": 0,
        "Religion": 0,
        "Sports": 0
    }

    genre_list = []

    for key, value in user_instance.rented_books.iteritems():
        genre_frequency_dict[load_serialized_ebook(value.isbn).genre] += 1

    frequency = 0
    for key, value in genre_frequency_dict.iteritems():
        if value >= frequency:
            genre_list.append(key)
            frequency = value
    return genre_list
Пример #3
0
def approve_book(isbn, username):
    """
    Approve a book and reward points
    :param isbn: str
    :param username: str
    :return:
    """
    book = load_serialized_ebook(isbn)
    book.approved = True
    add_user_credits(username, book.award_amount)
    update_serialized_ebook(book)
Пример #4
0
def approve_book(isbn, username):
    """
    Approve a book and reward points
    :param isbn: str
    :param username: str
    :return:
    """
    book = load_serialized_ebook(isbn)
    book.approved = True
    add_user_credits(username, book.award_amount)
    update_serialized_ebook(book)
Пример #5
0
def remove_ebook_with_infraction(isbn, infraction_reason, timestamp=None):
    book = load_serialized_ebook(isbn)
    user = load_serialized_user(book.uploader.username)
    user.credits -= (book.reward_amount + 100)
    user.infractions[isbn + str(datetime.datetime.now())] = infraction_reason
    check_infractions(user)
    serialize_user(user, user.username)
    delete_ebook_from_users(isbn)
    remove_ebook(isbn)
    if timestamp is not None:
        remove_report(isbn, timestamp)
Пример #6
0
def remove_ebook_with_infraction(isbn, infraction_reason, timestamp=None):
    book = load_serialized_ebook(isbn)
    user = load_serialized_user(book.uploader.username)
    user.credits -= (book.reward_amount + 100)
    user.infractions[isbn + str(datetime.datetime.now())] = infraction_reason
    check_infractions(user)
    serialize_user(user, user.username)
    delete_ebook_from_users(isbn)
    remove_ebook(isbn)
    if timestamp is not None:
        remove_report(isbn, timestamp)
Пример #7
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
Пример #8
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
Пример #9
0
def get_book_instance(isbn):
    return load_serialized_ebook(isbn)
Пример #10
0
def blacklist_book_uploader(isbn):
    book = load_serialized_ebook(isbn)
    user = load_serialized_user(book.uploader.username)
    user.is_blacklisted = True
    serialize_user(user, user.username)
Пример #11
0
def get_book_instance(isbn):
    return load_serialized_ebook(isbn)
Пример #12
0
def blacklist_book_uploader(isbn):
    book = load_serialized_ebook(isbn)
    user = load_serialized_user(book.uploader.username)
    user.is_blacklisted = True
    serialize_user(user, user.username)