Example #1
0
def menu():
    try:
        database.books = database.read_from_file('books.txt')
        database.reload_indexes()
    except FileNotFoundError:
        pass

    while True:
        user_input = input(f'{USER_CHOICE} \nWhat is your choice?')
        if user_input == 'a':
            database.add_book()
            database.book_index += 1
            database.save_to_file('books.txt', database.books)
        elif user_input == 'l':
            database.list_books()
        elif user_input == 'r':
            database.mark_as_read()
            database.save_to_file('books.txt', database.books)
        elif user_input == 'd':
            database.delete_book()
            database.save_to_file('books.txt', database.books)
        elif user_input == 'q':
            print('Goodbye')
            break
        else:
            print('Invalid option')
Example #2
0
def menu():
    global books
    user_input = input(user_choice)
    while user_input != 'q':
        if user_input == 'a':
            addBooks(books)
        elif user_input == 'l':
            list_books(books)
        elif user_input == 's':
            search_books(books)
        elif user_input == 'd':
            books = delete_book(books)
        elif user_input == 'r':
            books = mark_read(books)
        user_input = input(user_choice)
Example #3
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')
def menu():
	user_input = input(USER_CHOICE).strip().lower()
	while user_input != "q":
		if user_input == "a":
			database.add_books()
		elif user_input == "l":
			reading_list = database.list_all_books()
			if reading_list:
				database.list_books(reading_list)
			else:
				print("List is empty")
		elif user_input == "r":
			database.mark_book_as_read()
		elif user_input == "d":
			database.delete_books()
		else:
			print("Input is not valid, please enter again")

		user_input = input(USER_CHOICE).strip().lower()
Example #5
0
def main():

    # Get the database list data
    books = database.load_database_list()

    # Print the screen title
    print("***********************************")
    print("* Milestone 2 Project - Databases *")
    print("***********************************")

    # Build main menu list
    main_menu = [
        "Add a new book", "List all books", "Mark a book to read",
        "Delete a book", "Quit"
    ]

    while True:
        # list_menu() ensures that one of the choices has been selected
        choice = database.list_menu(main_menu, "Main Menu")
        if choice == 1:
            database.add_book(books)
        elif choice == 2:
            database.list_books(books)
        elif choice == 3:
            database.mark_book(books)
        elif choice == 4:
            books = database.delete_book(books)
        else:
            break

    # Exit gracefully

    database.save_database_list(books)

    # database.create_book_table()

    raise SystemExit(0)
Example #6
0
def list_books():
    for book in database.list_books():
        read = 'YES' if book.read else 'NO'
        print(f"{book.name} by {book.author} — Read: {read}")
Example #7
0
def list_books_prompt():
    database.list_books()
Example #8
0
def list_books():
    database.list_books()