Skip to content

Commit 1f98672

Browse files
Dictionary of list of dictionaries
1 parent b02326d commit 1f98672

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/python3
2+
"""get all information about all user and their completed task
3+
and get all the information about the user and the todo taska and
4+
the todos task which the user have not done.
5+
You cannot kill me with documentation"""
6+
import json
7+
import requests
8+
9+
if __name__ == "__main__":
10+
data = {}
11+
for i in range(1, 11):
12+
id = i
13+
url = "https://jsonplaceholder.typicode.com"
14+
res = requests.get('{}/users/{}'.format(url, id)).json()
15+
res_todo = requests.get("{}/todos".format(url),
16+
params={"userId": id}).json()
17+
name = res.get("username")
18+
user_data = list(map(
19+
lambda x: {
20+
"task": x.get("title"),
21+
"completed": x.get("completed"),
22+
"username": name
23+
},
24+
res_todo
25+
))
26+
data["{}".format(id)] = user_data
27+
with open('todo_all_employees.json', 'w') as apidata:
28+
json.dump(data, apidata)

0 commit comments

Comments
 (0)