mzalmeida

Milestone 2 - SQLite3 - main.py

Jan 26th, 2021
912
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from utils import mongo as database
  2.  
  3.  
  4. USER_CHOICE = """
  5. Enter:
  6. - 'a' to add a new book
  7. - 'l' to list all books
  8. - 'r' to mark a book as read
  9. - 'd' to delete a book
  10. - 'q' to quit
  11.  
  12. Your choice: """
  13.  
  14.  
  15. def menu():
  16.     user_input = input(USER_CHOICE)
  17.     while user_input != 'q':
  18.         if user_input == 'a':
  19.             prompt_add_book()
  20.         elif user_input == 'l':
  21.             list_books()
  22.         elif user_input == 'r':
  23.             prompt_read_book()
  24.         elif user_input == 'd':
  25.             prompt_delete_book()
  26.         else:
  27.             print("Unknown command. Please try again")
  28.  
  29.         user_input = input(USER_CHOICE)
  30.  
  31.  
  32. def prompt_add_book():
  33.     name = input('Enter the new book name: ')
  34.     author = input('Enter the new book author: ')
  35.  
  36.     database.add_book(name, author)
  37.  
  38.  
  39. def list_books():
  40.     books = database.get_all_books()
  41.     for book in books:
  42.         read = 'YES' if book['read'] else 'NO'
  43.         print(f"{book['name']} by {book['author']} — Read: {read}")
  44.  
  45.  
  46. def prompt_read_book():
  47.     name = input('Enter the name of the book you just finished reading: ')
  48.  
  49.     database.mark_book_as_read(name)
  50.  
  51.  
  52. def prompt_delete_book():
  53.     name = input('Enter the name of the book you wish to delete: ')
  54.  
  55.     database.delete_book(name)
  56.  
  57.  
  58. menu()
  59.  
RAW Paste Data