-
Notifications
You must be signed in to change notification settings - Fork 18
/
2-export_to_JSON.py
executable file
·41 lines (31 loc) · 1021 Bytes
/
2-export_to_JSON.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
#!/usr/bin/python3
"""
Script that, using this REST API, for a given employee ID, returns
information about his/her TODO list progress
and export data in the JSON format.
"""
import json
import requests
from sys import argv
if __name__ == "__main__":
sessionReq = requests.Session()
idEmp = argv[1]
idURL = 'https://jsonplaceholder.typicode.com/users/{}/todos'.format(idEmp)
nameURL = 'https://jsonplaceholder.typicode.com/users/{}'.format(idEmp)
employee = sessionReq.get(idURL)
employeeName = sessionReq.get(nameURL)
json_req = employee.json()
usr = employeeName.json()['username']
totalTasks = []
updateUser = {}
for all_Emp in json_req:
totalTasks.append(
{
"task": all_Emp.get('title'),
"completed": all_Emp.get('completed'),
"username": usr,
})
updateUser[idEmp] = totalTasks
file_Json = idEmp + ".json"
with open(file_Json, 'w') as f:
json.dump(updateUser, f)