-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
61 lines (45 loc) · 1.61 KB
/
main.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
# Main App -- Storing Books in the Database + Type Hinting + SQLite3
from utils import database
USER_CHOICE = """
Enter following for :
- 'a' to ADD a New Book.
- 'l' to LIST all the Books.
- 'r' to MARK a Book as Read.
- 'd' to DELETE a Book.
- 'q' to QUIT the App.
Your Choice : """
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)
def prompt_add_book():
name = input('Enter the Name of the Book : ')
author = input('Enter the Name of the Author : ')
database.add_book(name, author)
print('--> Book Added Successfully..!')
def list_books():
books = database.get_all_books()
for book in books:
read = 'YES' if book['read'] else 'NO'
print(f'{book["name"]} by {book["author"]} and read: {read}')
print('----------------------------------')
def prompt_read_book():
name = input('Enter the Name of the Book, you\'ve just finish Reading : ')
database.mark_book_as_read(name)
print(f'--> \"{name}\" Marked as Read')
def prompt_delete_book():
name = input('Enter the Book Name, you wish to Delete : ')
database.delete_book(name)
print('--> Book has been deleted successfully..!')
menu()