-
Notifications
You must be signed in to change notification settings - Fork 0
/
json_performer.py
70 lines (55 loc) · 1.47 KB
/
json_performer.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
62
63
64
65
66
67
import json
import pprint
def get_dirs(js_f):
"""
show the keys of the dict and let user select
:param js_f:
:return: str
"""
for i in js_f.keys():
print(i)
selected = input('Select key, which you want: ')
if selected in js_f.keys():
return selected
def get_users(users):
"""
creates users dict of type {username: users info dict}
:param users: list(dicts)
:return: dict
"""
users_dict = dict()
for user_object in users:
username = user_object['name']
users_dict[username] = user_object
return users_dict
def select_user(users):
"""
provides options to select for user
:param users:
:return: dict
"""
for user in users.keys():
print(user)
selected_user = input("Select the user you want to get info about ")
return users[selected_user]
def interact_with_user(js_f):
"""
interacts with user, does the main work
:param js_f:
:return: nothing
"""
key = get_dirs(js_f)
if type(js_f[key]) == dict:
get_dirs(js_f[key])
elif key == 'users':
user_dict = get_users(js_f['users'])
selected_user = select_user(user_dict)
interact_with_user(selected_user)
else:
pprint.pprint(js_f[key])
print(type(js_f[key]))
print("That's it")
if __name__ == '__main__':
with open('user_friends.json', 'r', encoding='utf-8') as f:
js = json.load(f)
interact_with_user(js)