-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
36 lines (24 loc) · 854 Bytes
/
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
from address_book import AddressBook
from commands import get_command
ADDRESS_BOOK_FILENAME = "address_book.pickle"
def parse_input(user_input):
cmd, *args = user_input.split()
cmd = cmd.strip().lower()
return cmd, *args
def main():
address_book = AddressBook()
address_book.load(ADDRESS_BOOK_FILENAME)
print("Welcome to the assistant bot!")
while True:
user_input = input("Enter a command: ")
command_name, *args = parse_input(user_input)
command_object = get_command(command_name)
if command_object:
print(f"\n{command_object.execute(address_book, args)}\n")
if command_object.is_final:
address_book.save(ADDRESS_BOOK_FILENAME)
break
else:
print("Unknown command.")
if __name__ == "__main__":
main()