-
Notifications
You must be signed in to change notification settings - Fork 0
/
0-gather_data_from_an_API.py
33 lines (29 loc) · 1.01 KB
/
0-gather_data_from_an_API.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
#!/usr/bin/python3
'''
Returns information about TODO list progress from a REST API given an employee ID
'''
import requests
from sys import argv
def display():
"""return API data"""
users = requests.get("http://jsonplaceholder.typicode.com/users")
for user in users.json():
if user.get('id') == int(argv[1]):
EMPLOYEE_NAME = (user.get('name'))
break
TOTAL_NUM_OF_TASKS = 0
NUMBER_OF_DONE_TASKS = 0
TASK_TITLE = []
todos = requests.get("http://jsonplaceholder.typicode.com/todos")
for todo in todos.json():
if todo.get('userId') == int(argv[1]):
TOTAL_NUM_OF_TASKS += 1
if todo.get('completed') is True:
NUMBER_OF_DONE_TASKS += 1
TASK_TITLE.append(todo.get('title'))
print("Employee {} is done with tasks({}/{}):"
.format(EMPLOYEE_NAME, NUMBER_OF_DONE_TASKS, TOTAL_NUM_OF_TASKS))
for task in TASK_TITLE:
print("\t {}".format(task))
if __name__ == "__main__":
display()