-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_hw10_my2.py
More file actions
83 lines (62 loc) · 1.87 KB
/
main_hw10_my2.py
File metadata and controls
83 lines (62 loc) · 1.87 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from collections import UserDict
from normalize_phone import normalize_phone
COMMAND_EXIT = ['good bye', 'close', 'exit']
contacts_dict = [{"name": "Artem", "phone": "+380504848484"},
{"name": "Ira", "phone": "+380501111111"},
{"name": "Diana", "phone": "+380502222222"},]
COMMAND_DICT = {
hello_func: "hello",
add_func: "add",
show_all: "show all",
change_contact: "change",
phone_print: "phone"
}
from collections import UserDict
class Field:
def __init__(self, value) -> None:
self.value = value
class Name(Field):
pass
class Phone(Field):
pass
class Record():
def __init__(self, name:Name, phone:Phone=None) -> None:
self.name = name
self.phones = []
if phone:
self.phones.append(phone)
class AddressBook(UserDict):
def add_record(self, rec:Record):
self.data[rec.name.value] = rec
print(self)
def select_command(text):
for key, val in COMMAND_DICT.items():
if val == text:
return key
return f'non command in list'
def parser_text(text):
text = text.lower().strip()
if text.startswith("show all"):
return "show all", None
else:
user_text = text.split()
return user_text[0], user_text[1:]
def main():
while True:
user_input = input('>>input>>')
if user_input.lower().strip() in COMMAND_EXIT:
print('Good bye!')
break
user_command, other_text = parser_text(user_input)
result = select_command(user_command)
if type(result) == str:
print(result)
else:
print(result(other_text))
if __name__ == "__main__":
main()
# artem = AddressBook()
# # # print(artem.addressbook)
# # print(artem.add_record('artem'))
# ira = Test('ira')
# print(ira.data)