diff --git a/main.py b/main.py new file mode 100644 index 0000000..607adba --- /dev/null +++ b/main.py @@ -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) \ No newline at end of file diff --git a/utils.py b/utils.py new file mode 100644 index 0000000..3384139 --- /dev/null +++ b/utils.py @@ -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 \ No newline at end of file