-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
63 lines (40 loc) · 1.35 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from utils import database
USER_CHOICES = """
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: """
def menu():
database.create_book_table()
user_input = input(USER_CHOICES)
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_CHOICES)
def prompt_add_book():
name = input('Enter the title of the book: ')
author = input('Enter the author: ')
database.add_book(name, author)
def list_books():
books = database.get_all_books()
for i, book in enumerate(books):
read = 'YES' if book['read'] else 'NO'
print(f"{str(i + 1).zfill(2)} - {book['name']} by {book['author']}, read: {read}")
def prompt_read_book():
name = input("Enter the name of the book you just finished reading: ")
database.mark_book_as_read(name)
def prompt_delete_book():
name = input("Enter the name of the book you wish to delete: ")
database.delete_book(name)
menu()