Esempio n. 1
0
def search_book():
    search_option, search_value = ui.search_by()

    if search_option == "id":
        search_book = datastore.get_books(id=search_value)
    elif search_option == "title":
        search_book = datastore.get_books(title=str(search_value))
    elif search_option == "author":
        search_book = datastore.get_books(author=str(search_value))
    elif search_option == "rating":
        search_book = datastore.get_books(rating=search_value)

    ui.show_list(search_book)
Esempio n. 2
0
def delete_books():
    '''Search for a user specified book title to to delete'''

    global book_list
    global counter
    mySearch = ui.get_search_string()
    searchResult = datastore.get_books(search=mySearch)

    if searchResult != 'not found':
        while True:
            confirm = input(
                "Book Found.\nDo you really want to delete this book? 'y'es or 'n'o "
            ).strip().lower()
            if confirm.lower() == "y":
                #position = fileio.book_list.index(str(searchResult))
                #print(position)

                #removed = fileio.book_list.pop(position)
                removed = datastore.delete_book(searchResult)

                #print ("Successfully Deleted:", searchResult,"\n")
                print("Successfully Deleted:", removed,
                      "\n")  # changed to print removed - Jeremy
                break

            elif confirm != "y":
                break
    else:
        print('The book was NOT found')
Esempio n. 3
0
def show_unread():

    '''Fetch and show all unread books'''
    # getting all the unread books in the data store
    unread = datastore.get_books(read=False)
    # uses the ui program to print out the books or to say no books in list
    ui.show_list(unread)
Esempio n. 4
0
def search_book():
    books_to_search = datastore.get_books()
    search_id = int(input('Enter book\'s id to begin search: '))
    books = [book for book in books_to_search if book.id == search_id]
    if len(books) == 0:
        ui.message('Book not found.')
    else:
        for b in books:
            print(b)
Esempio n. 5
0
def search_books():
    '''Search for a user specified book title and notify the user if found'''

    mySearch = ui.get_search_string()
    searchResult = datastore.get_books(search=mySearch)
    if searchResult != 'not found':
        print('This book was found: ', searchResult)
    else:
        print('The book was NOT found')
Esempio n. 6
0
def show_unread():
    '''Fetch and show all unread books, sorted as requested by user.'''
    unread = datastore.get_books(read=False)
    preference = ui.get_sort_info('n')
    if preference == '1':
        ui.show_list(datastore.sort_list('title', unread))
    elif preference == '2':
        ui.show_list(datastore.sort_list('author', unread))
    elif preference == '3':
        ui.show_list(unread)
Esempio n. 7
0
def search_list():
    '''Search for a book'''
    search = (input('Enter a title '))
    all_search = datastore.get_books()
    wanted_books = [book for book in all_search if book.title == search]

    if len(wanted_books) == 0:
        print('book not found')
    else:
        for g in wanted_books:
            print(g)
Esempio n. 8
0
def show_read():
    '''Fetch and show all read books, sorted as requested by user.'''
    read = datastore.get_books(read=True)
    preference = ui.get_sort_info('r')
    if preference == '1':
        ui.show_list(datastore.sort_list('title', read))
    elif preference == '2':
        ui.show_list(datastore.sort_list('author', read))
    elif preference == '3':
        ui.show_list(datastore.sort_list('rating', read))
    elif preference == '4':
        ui.show_list(read)
Esempio n. 9
0
def delete_book():
    '''Search for a book'''
    search = (input('Enter a title '))
    all_search = datastore.get_books()
    wanted_books = [book for book in all_search if book.title == search]

    if len(wanted_books) == 0:
        print('book not found')
    else:
        for g in wanted_books:
            ui.message('Book deleted: ' + str(g))
            wanted_books.remove(g)
Esempio n. 10
0
def search_book():
    ''' Get search term from user, if keyword exists, append book, show search results '''
    search_results = []
    all_books = datastore.get_books()
    search_term = ui.get_search_term()
    for book in all_books:
        if search_term in book.title:
            search_results.append(book)
        elif search_term in book.author:
            search_results.append(book)

    ui.message("Here's what I found:")
    ui.show_list(search_results)
Esempio n. 11
0
def show_read():
    '''Fetch and show all read books'''
    read = datastore.get_books(read=True)
    ui.show_list(read)
    if len(read) > 0:
        sort_choice = ui.display_sort_options()
        handle_sort_choice(sort_choice)
        if sort_choice == '1':
            s_list = sorted(read, key=s_author)
            ui.show_list(s_list)
        elif sort_choice == '2':
            s_list = sorted(read, key=s_title)
            ui.show_list(s_list)
Esempio n. 12
0
def sort_book():
    '''Sort the books either by title or by author'''
    books_to_sort = datastore.get_books()
    sortBook = int(input('Enter the sort option. 1 = title, 2 = author: '))
    while True:
        if (sortBook == 1):
            sorted_books = sorted(books_to_sort, key=lambda book: book.title)
            ui.show_list(sorted_books)
            break
        elif (sortBook == 2):
            sorted_books = sorted(books_to_sort, key=lambda book: book.author)
            ui.show_list(sorted_books)
            break
        else:
            sortBook = int(
                input('Enter the correct options (1 = title, 2 = author): '))
Esempio n. 13
0
def sort_list():
    '''sort the books'''
    allBooks = datastore.get_books()
    sortBooksByTitle = sorted(allBooks, key=lambda book: book.title)
    sortbooksByAuthor = sorted(allBooks, key=lambda book: book.author)
    sortBy = int(input('Enter 1 to sort by title and 2 to sort by auther: '))
    while True:
        if (sortBy == 1):
            ui.show_list(sortBooksByTitle)
            break
        elif (sortBy == 2):
            ui.show_list(sortbooksByAuthor)
            break
        else:
            print('The entry was incorrect.')
            sortBy = int(input('Enter the correct options: '))
Esempio n. 14
0
def show_read():
    """Fetch and show all read books"""
    read = datastore.get_books(read=True)
    ui.show_list(read)
Esempio n. 15
0
def search_book():
    """Fetch and show all read books"""
    search_string = input("Input the title or author of book: ")
    searched = datastore.get_books(string=search_string)
    ui.show_list(searched)
    pass
Esempio n. 16
0
def show_unread():
    '''Fetch and show all unread books'''
    unread = datastore.get_books(read=False)
    ui.show_list(unread)
Esempio n. 17
0
def show_read():
    '''Fetch and show all read books'''
    read = datastore.get_books(read=True)
    ui.show_list(read)
Esempio n. 18
0
def search_book():
    '''Fetch search books'''
    searchBooks = datastore.get_books(search=True)
    ui.show_list(searchBooks)