Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
## Steps to follow:
#### Create an API function:
- Import necessary library for making an API call.
- Make the API call to this URL -> `http://jsonplaceholder.typicode.com/users`
- Make the API call to this URL -> `http://jsonplacehoclelder.typicode.com/users`
- Check the status code, return object (res.json())
- Wrap the API function in try/except block.
- Return the return object.
Expand Down
22 changes: 22 additions & 0 deletions Random User Creator App/api_call.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import sys
import requests






def make_api_call():
"""
make an api call.
"""
try:
r = requests.get("http://jsonplaceholder.typicode.com/users")
if r.status_code >= 400:
raise requests.exceptions.HTTPError("No internet connection")
except requests.exceptions.HTTPError as e:
print(e)
sys.exit()
else:
result_object = r.json()
return result_object
14 changes: 14 additions & 0 deletions Random User Creator App/clean_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@


def cleaning_json_file(result_object):
"""cleaning json file
"""
new_lst = []
for i in range (0,10):
new_lst.append(result_object[i]["id"])
new_lst.append(result_object[i]["name"])
new_lst.append(result_object[i]["username"])
new_lst.append(result_object[i]["email"])
return new_lst


25 changes: 25 additions & 0 deletions Random User Creator App/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from api_call import *
from clean_file import *
from save_file import *
import sys
import requests






raw_list = make_api_call()
clean_file = cleaning_json_file(raw_list)
save_file = save_to_file(clean_file)











10 changes: 10 additions & 0 deletions Random User Creator App/save_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import json





def save_to_file(obj):
with open ("result.json","w") as f:
json.dump(obj, f)

Loading