-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.py
More file actions
48 lines (41 loc) · 1.37 KB
/
functions.py
File metadata and controls
48 lines (41 loc) · 1.37 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
import json
from uuid import uuid4
def load_phonebook(phone_book_file):
with open(phone_book_file, 'r', encoding='utf-8') as file:
phone_book_dict = file.read()
return json.loads(phone_book_dict)
def check_phonebook_is_loaded(phone_book_dict):
return phone_book_dict
def save_phonebook(new_book_file, phone_book):
data = json.dumps(phone_book, indent=4, ensure_ascii=False)
with open(new_book_file, 'w', encoding='utf-8') as file:
file.write(str(data))
def show_all_contacts(phone_book):
for k, v in phone_book.items():
print(f'ID: {k}')
for k, v in v.items():
print(f'{k}: {v}')
print()
def create_contact():
pass
def find_by_any(phone_book, searchstr):
#for k, v in phone_book.items():
print()
if searchstr in phone_book.keys(): #Поиск по ID
print()
print(f'ID: {searchstr}')
for k, v in phone_book[searchstr].items():
print(f'{k}: {v}')
print()
else:
print()
for k, v in phone_book.items():
if isinstance(v, dict):
for kk, vv in v.items():
if searchstr in vv:
print(f'ID: {k}')
for k, v in v.items():
print(f'{k}: {v}')
print()
def generate_userid():
return str(uuid4())[-12:]