-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
80 lines (45 loc) · 1.27 KB
/
Copy pathapp.py
File metadata and controls
80 lines (45 loc) · 1.27 KB
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
64
# -*- coding: utf-8 -*-
# @Author: gustavotamascohotmail.com
# @Date: 2022-02-11 08:47:36
# @Last Modified by: gustavotamascohotmail.com
# @Last Modified time: 2022-02-11 11:57:41
from utils import database_manager
def menu():
USER_CHOICE = input("""
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: """)
return USER_CHOICE
def prompt_add():
name = input("Enter the book name: ")
author = input("Enter author: ")
database_manager.insert_book(name, author)
def prompt_list():
for book in database_manager.get_all_books():
read = "Yes" if book["read"]==1 else "No"
print(f"The book {book['name']} by {book['author']}, is read {read}")
def prompt_read():
name = input("Enter the name of ther book you finished reading: ")
database_manager.mark_book_as_read(name)
def prompt_delete():
name = input("Enter the name of the book you want to delete: ")
database_manager.delete_book(name)
def main():
execute = {
"a": prompt_add,
"l": prompt_list,
"r": prompt_read,
"d": prompt_delete
}
database_manager.create_table()
user_input = menu()
while user_input != "q":
task = execute[user_input]
task()
user_input = menu()
if __name__=='__main__':
main()