Skip to content

Commit

Permalink
Add project file for Task 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Duffigoogle committed Oct 18, 2022
1 parent a4ae937 commit 0417951
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions 0x15-api/3-dictionary_of_list_of_dictionaries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/python3
"""Exports data in the JSON format"""

if __name__ == "__main__":

import json
import requests
import sys

users = requests.get("https://jsonplaceholder.typicode.com/users")
users = users.json()
todos = requests.get('https://jsonplaceholder.typicode.com/todos')
todos = todos.json()
todoAll = {}

for user in users:
taskList = []
for task in todos:
if task.get('userId') == user.get('id'):
taskDict = {"username": user.get('username'),
"task": task.get('title'),
"completed": task.get('completed')}
taskList.append(taskDict)
todoAll[user.get('id')] = taskList

with open('todo_all_employees.json', mode='w') as f:
json.dump(todoAll, f)

0 comments on commit 0417951

Please sign in to comment.