-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2-export_to_JSON.py
More file actions
executable file
·34 lines (27 loc) · 884 Bytes
/
2-export_to_JSON.py
File metadata and controls
executable file
·34 lines (27 loc) · 884 Bytes
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
#!/usr/bin/python3
"""
A Python 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__':
EMPLOYEE_ID = argv[1]
USER_URL = "https://jsonplaceholder.typicode.com/users"
URL = USER_URL + "/" + EMPLOYEE_ID
response = requests.get(URL)
USERNAME = response.json().get('username')
TODO_URL = URL + "/todos"
response = requests.get(TODO_URL)
tasks = response.json()
dic = {EMPLOYEE_ID: []}
for task in tasks:
dic[EMPLOYEE_ID].append({
"task": task.get('title'),
"completed": task.get('completed'),
"username": USERNAME
})
with open('{}.json'.format(EMPLOYEE_ID), 'w', encoding='UTF-8') as f:
json.dump(dic, f)