forked from fenyx-it-academy/Class7-Python-Module-Week3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
36 lines (26 loc) · 831 Bytes
/
utils.py
File metadata and controls
36 lines (26 loc) · 831 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
35
36
import json
from re import M
import requests
def make_api(link):
try :
r=requests.get(link)
assert r.status_code >=200 and r.status_code <=300
except:
print('Error')
else:
return r.json()
def cleaning(dic):
""" This would return a new dict , each key is an id for a user, each value for this key is another dict that contains
other details, (id, name, user, email)
"""
cleaned = {}
for i in range(len(dic)) :
cleaned [str(i+1)]={}
cleaned [str(i+1)]['id']=i+1
cleaned [str(i+1)] ['name']=dic[i]['name']
cleaned [str(i+1)] ['username']=dic[i]['username']
cleaned [str(i+1)] ['email']=dic[i]['email']
return cleaned
def to_json(dic):
with open('json_file.json', 'w') as j :
json.dump(dic, j)