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
8 changes: 8 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from utils import api_call, clean_result, saved, user_id

user_id_no = user_id()
result_list = api_call()

clean_dct = clean_result(dic=result_list,id_no=user_id_no)

saved(obj=clean_dct,id=user_id_no)
47 changes: 47 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import requests
import json


def saved(obj,id):


with open(f"User {id} .json", "w") as f:
json.dump(obj, f)


def api_call():

"""an api call and user info
return: user info
"""
res = requests.get('http://jsonplaceholder.typicode.com/users')
result_obj = res.json()
return result_obj

def clean_result(dic,id_no):


new_dic = {
"UserID": dic[id_no-1]['id'],
"Name": dic[id_no-1]['name'],
"UserName": dic[id_no-1]['username'],
"E-mail": dic[id_no-1]['email']
}
return new_dic

def user_id():
"""random user picker
return: int: user id
"""
print("Welcome to the UserID App!")

try:
user_id_no=int(input('"Type a number between 1 and 10: '))
assert 1<= user_id_no<=10

except ValueError:
print('Please enter a valid input')
except AssertionError:
print("Please Enter a number between 1 and 10")

return user_id_no