コード例 #1
0
def menu():
    database.create_book_table()

    user_input = input(USER_CHOICE)
    while user_input != "q":

        if user_input == "a":
            prompt_add_book()

        elif user_input == "d":
            prompt_delete_book()

        elif user_input == "l":
            prompt_get_all_books()

        elif user_input == "r":
            prompt_mark_book_as_read()

        elif user_input == "nr":
            prompt_mark_book_as_not_read()

        else:
            print("Invalid input!")

        user_input = input(USER_CHOICE)

    else:
        print("\nYou have logged out of your account.\n")
コード例 #2
0
ファイル: app.py プロジェクト: salujaparam/python_udemy
def menu():
    database.create_book_table()
    ans = input(
        '-a for adding a book,\n-r for marking a book as read,\n-l for listing all the books,\n-d for deleting a book and\n-q to quit.'
    )
    while (ans != 'q'):
        if ans == 'a':
            name = input('Name of the book: ')
            author = input('Author of th book: ')
            database.add(name, author)
        elif ans == 'r':
            name = input('Name the book you want to mark as read? ')
            database.read(name)
            print('\n The book has been marked as read \n')
        elif ans == 'l':
            books = database.all_books()

            for book in books:
                if len(books) == 0:
                    print('\n No books to show \n')
                    break
                print('\nName of the book:', book['name'])
                print('Author of the book: ', book['author'])
                print('Has the book been read?', book['read'], '\n')
        elif ans == 'd':
            name = input('Name the book you want to delete? ')
            database.delete_book(name)
            print('\n The book has been deletd \n')
        else:
            print('Enter correctly...')

        ans = input(
            '-a for adding a book,\n-r for marking a book as read,\n-l for listing all the books,\n-d for deleting a book and\n-q to quit.'
        )
コード例 #3
0
def list_books():
    try:
        books = database.get_all_books()
    except FileNotFoundError:
        database.create_book_table()
        books = database.get_all_books()
    for book in books:
        read = "YES" if book['read'] else "NO"
        print(f"{book['name']} by {book['author']}, read: {read}")
コード例 #4
0
def menu():
    database.create_book_table()
    while True:
        user_input = input(choice)
        try:
            operation = action[user_input]
            if operation == exit_app:
                operation()
                break
            operation()
        except KeyError:
            print("Choose valid operation from given the menu...")
コード例 #5
0
ファイル: app.py プロジェクト: joegurr/python-books-cli
def menu():
    database.create_book_table()
    user_input = input(USER_CHOICE)
    while user_input != "q":
        if user_input in USER_OPTIONS:
            USER_OPTIONS[user_input]()
        else:
            print("Unknown command, please try again")

        user_input = input(SIMPLE_USER_CHOICE)

    print("Thanks, bye")
コード例 #6
0
ファイル: app.py プロジェクト: mcastillo40/python-examples
def menu():
    database.create_book_table()
    user_input = input(USER_CHOICE)

    while user_input != 'q':
        print("\n")
        if user_input in user_options:
            selected_action = user_options[user_input]
            selected_action()
        else:
            print("Unknown Command. Please try again")

        user_input = input(USER_CHOICE)
コード例 #7
0
def menu():
    database.create_book_table()
    user_input = input(USER_CHOICE)
    while user_input != 'q':
        if user_input == 'a':
            prompt_add_book_to_the_list()
        elif user_input == 'l':
            list_all_books()
        elif user_input == 'r':
            prompt_mark_book_as_read()
        elif user_input == 'd':
            prompt_to_delete_a_book()

        user_input = input(USER_CHOICE)
コード例 #8
0
def menu():
    database.create_book_table()
    user_input = input(USER_CHOICE)
    while user_input != 'q':
        if user_input == 'a':
            prompt_add_book()
        elif user_input == 'l':
            list_books()
        elif user_input == 'r':
            prompt_read_book()
        elif user_input == 'd':
            prompt_delete_book()

        user_input = input(USER_CHOICE)
コード例 #9
0
def menu():
    database.create_book_table()
    user_input = input(USER_CHOICE)
    while user_input != 'q':
        if user_input == 'a':
            prompt_add_book()
        elif user_input == 'l':
            list_books()
        elif user_input == 'r':
            prompt_read_book()
        elif user_input == 'd':
            prompt_delete_book()
        else:
            print('Entered command is invalid .Please insert valid command')
        user_input = input(USER_CHOICE)
コード例 #10
0
def menu():
    database.create_book_table()
    user_input = input(USER_CHOICE)
    while user_input != 'q':
        if user_input == 'a':
            prompt_add_book()
        elif user_input == 'l':
            list_books()
        elif user_input == 'r':
            prompt_read_book()
        elif user_input == 'd':
            prompt_delete_book()
        else:
            print('Please enter valid choice')
        user_input = input(USER_CHOICE)
コード例 #11
0
def menu():
    database.create_book_table()
    user_input = input(USER_CHOICE).lower()
    while user_input != "q":
        if user_input == "a":
            add_book()
        elif user_input == "l":
            list_book()
        elif user_input == "r":
            read_book()
        elif user_input == "d":
            delete_book()
        else:
            print("Command unknown!")
        user_input = input(USER_CHOICE).lower()
コード例 #12
0
def menu():
    database.create_book_table()
    user_input = input(USER_CHOICE)
    while user_input != 'q':
        if user_input == 'a':
            prompt_add_book()
        elif user_input == 'l':
            list_books()
        elif user_input == 'r':
            prompt_read_book()
        elif user_input == 'd':
            prompt_delete_book()
        else:
            print("Unknown command. Please try again.")
        user_input = input(USER_CHOICE)
コード例 #13
0
ファイル: app.py プロジェクト: Mark-Pasq/Home_Library_Project
def menu():
    database.create_book_table()
    user_input = input(USER_CHOICE)
    while user_input != 'q':
        if user_input == 'a':
            prompt_add_book_to_the_list()
        elif user_input == 'l':
            list_all_books()
        elif user_input == 'r':
            prompt_mark_book_as_read()
        elif user_input == 'd':
            prompt_to_delete_a_book()
        else:
            print('unknown command or input!  Try your selection again')

        user_input = input(USER_CHOICE)
コード例 #14
0
ファイル: app.py プロジェクト: ferran9908/Python-Course
def menu():
    database.create_book_table()
    user_input = input(USER_CHOICE)
    while user_input != "q":
        if user_input == "a":
            prompt_add()
        elif user_input == "l":
            list_books()
        elif user_input == "r":
            prompt_read_book()
        elif user_input == "d":
            prompt_delete_book()
        else:
            print("Unknown Command")

        user_input = input(USER_CHOICE)
コード例 #15
0
ファイル: app.py プロジェクト: Ahlammmmm/milestone_SQL
def menu():
    database.create_book_table()
    user_input = input(USER_CHOICE)
    while user_input != 'q':
        if user_input == 'a':
            prompt_add_book()
        elif user_input == 'l':
            list_books()
        elif user_input == 'r':
            prompt_read_book()
        elif user_input == 'd':
            prompt_delete_book()
        else:
            print("Unknown command please enter the right one (a, l, r, d, q)")

        user_input = input(USER_CHOICE)
コード例 #16
0
def menu():
    user_input = input(USER_CHOICE)
    database.create_book_table()

    while user_input != 'q':
        if user_input == 'a':
            prompt_add_book()
        elif user_input == 'l':
            list_books()
        elif user_input == 'r':
            prompt_read_book()
        elif user_input == 'd':
            prompt_delete_book()
        else:
            print('Unknown Command. Please Try Again..!!')

        user_input = input(USER_CHOICE)
コード例 #17
0
def menu():
    database.create_book_table()
    while True:
        user_input = input(USER_CHOICE)
        if user_input == 'a':
            prompt_add_book()
        elif user_input == 'l':
            list_book()
        elif user_input == 'r':
            prompt_read_book()
        elif user_input == 'd':
            prompt_delete_book()
        elif user_input == 'q':
            print('\n[*] Bye...\n')
            break
        else:
            print('[-] Invalid command! Insert a valid command.')
コード例 #18
0
def menu():
    database.create_book_table()
    while True:
        user_input = input(user_choice).lower()
        if user_input == 'a':
            prompt_add_book()
        elif user_input == 'l':
            list_books()
        elif user_input == 'r':
            prompt_read_book()
        elif user_input == 'd':
            prompt_delete_book()
        elif user_input == 'q':
            print('Exiting the bookstore, see you next time!')
            break
        else:
            print('Error reading input, please try again...')
コード例 #19
0
def menu():
    """The menu of the application"""
    database.create_book_table()
    user_input = input(USER_CHOICE)
    while user_input != 'q':
        if user_input == 'a':
            prompt_add_book()
        elif user_input == 'l':
            list_books()
        elif user_input == 'f':
            find_book()
        elif user_input == 'r':
            prompt_read_book()
        elif user_input == 'd':
            prompt_delete_book()
        else:
            print("Unknown command. Please try again")
        user_input = input(USER_CHOICE)
コード例 #20
0
ファイル: app.py プロジェクト: amssdias/python-books_db
def menu():
    database.create_book_table()
    menu = {
        'a': prompt_add_book,
        'l': list_books,
        'r': prompt_read_book,
        'd': prompt_delete_book
    }

    user_input = input(USER_cHOICE)

    while user_input != 'q':
        try:
            user_option = menu[user_input]
            user_option()
        except KeyError:
            print('Unknown command. Please try again.')

        user_input = input(USER_cHOICE)
コード例 #21
0
def menu():
    database.create_book_table()
    user_input = input(USER_CHOICE)
    while user_input != 'q':
        if user_input == 'a':
            name = input("Enter the name of the book: ")
            author = input("Enter the author of the book: ")
            database.add_book(name, author)
            user_input = input(USER_CHOICE)
        elif user_input == 'l':
            list_books()
            user_input = input(USER_CHOICE)
        elif user_input == 'r':
            mark_book_as_read()
            user_input = input(USER_CHOICE)

        elif user_input == 'd':
            delete_prompt_book()
            user_input = input(USER_CHOICE)
コード例 #22
0
def menu():

    database.create_book_table()

    while True:
        user_input = input(f'{USER_CHOICE} \nWhat is your choice?')
        if user_input == 'a':
            database.add_book()
        elif user_input == 'l':
            database.list_books()
        elif user_input == 'r':
            database.mark_as_read()
        elif user_input == 'd':
            database.delete_book()
        elif user_input == 'q':
            print('Goodbye')
            break
        else:
            print('Invalid option')
コード例 #23
0
ファイル: app.py プロジェクト: aliemekestephen/bookList
def menu():  # function to select the active function to run
    database.create_book_table()
    user_input = input(USER_CHOICE)
    while user_input != 'q':
        if user_input == 'a':  # from this point
            prompt_add_book()
        elif user_input == 'l':
            list_book()
        elif user_input == 'r':
            prompt_read_book()
        elif user_input == 'd':
            delete_book()  # to this point
        else:
            print("Unknown command. Please try again.")

# another way to implement the set of if statements using first class functions
        #if user_input in user_options:
            #active_function = user_options[user_input]
            #active_function()

        user_input = input(USER_CHOICE)
コード例 #24
0
def menu():
    db.create_book_table()
    user_input = input(USER_CHOICE)

    while user_input != 'q':
        try:
            if user_input == 'a':
                add_book()
            elif user_input == 'l':
                show_books()
            elif user_input == 'r':
                mark_read_book()
            elif user_input == 'd':
                delete_book()
            else:
                print('Unknown command')
        except Exception as x:
            print(
                f"Unexpected exception: type: {x.__class__.__name__}, content: {x}"
            )
        finally:
            user_input = input(USER_CHOICE)
コード例 #25
0
def menu():
    database.create_book_table()
    user_input = input(USER_CHOICE)
    while user_input != "q":
        if user_input == "a":
            name = input("Enter book name:")
            author = input("Enter book author:")
            database.a(name, author)
        elif user_input == "r":
            user_input = input("What title are you reading?: ")
            database.r(user_input)
        elif user_input == "l":
            books = database.get_all_books()
            for book in books:
                database.l(book)

        elif user_input == "d":
            user_input = input("What title would like to delete: ")
            database.d(user_input)
        elif user_input == "q":
            break
        else:
            print("Unknown command. Please try again!")
        user_input = input(USER_CHOICE)
コード例 #26
0
def menu():
    database.create_book_table()
    pass
コード例 #27
0
def json_check():
    if not database.books_file.exists(): # creates
        database.create_book_table()
コード例 #28
0
ファイル: app.py プロジェクト: DavorKandic/My_Books_App-DB
from utils import database as db


USER_CHOICE = """
Enter:
- 'a' to add a new book
- 'l' to list all books
- 'r' to mark a book as read
- 'd' to delete a book
- 'q' to quit

Your choice:"""


db.create_book_table()

def menu():
    user_input = input(USER_CHOICE)
    while user_input != 'q':
        if user_input == 'a':
            prompt_add_book()
        elif user_input == 'l':
            list_books()
        elif user_input == 'r':
            prompt_read_book()  
        elif user_input == 'd':
            prompt_delete_book()  
        else:
            print('Unknown input. Please, try again.')
                
        user_input = db.take_input()
コード例 #29
0
    :return:
    """
    books = database.get_all_books()
    print('List of books:')
    for book in books:
        read = 'YES' if book['read'] == 1 else 'NO'
        print(f"{ book['name'] } by { book['author'] }, read: { read }")


def prompt_read_book():
    """
    Ask for book name and change it to 'Read' in our list
    :return:
    """
    name = input('Enter the name of the book you just finished reading: ')
    database.mark_book_as_read(name)


def prompt_delete_book():
    """
    Ask for book name and delete it to 'Read' in our list
    :return:
    """
    name = input('Enter the name of the book you wish to delete: ')
    database.delete_book(name)


if __name__ == '__main__':
    database.create_book_table()
    menu()