From 8df3f2445f593460a8642458f9f8d4452fcc7b39 Mon Sep 17 00:00:00 2001 From: SefaSAHAN Date: Tue, 11 Oct 2022 18:29:43 +0200 Subject: [PATCH] Execption_file_Venv_homework --- main.py | 8 +++++++ requirements.txt | Bin 0 -> 190 bytes utils.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 main.py create mode 100644 requirements.txt create mode 100644 utils.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..a5c978d --- /dev/null +++ b/main.py @@ -0,0 +1,8 @@ +from utils import * + +user_id_number = user_id() +result_list = make_api_call() + +clean_dct = clean_result(dct=result_list,id_number=user_id_number) + +save_file(obj=clean_dct,id=user_id_number) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..94b56f0506a85ea448a60de6e3bc927fa60cbc09 GIT binary patch literal 190 zcmX|)OA3QP5Cv;3c$7$NLof>uqb4DOA9Qq+!^b>Zk>L$=Q?Gjc)x4OPX?QDzo^e%- zgok3>h>58AP>KxVXD;*%nmX-T^}cS|+X<<9ska)QB1`vX+U~AN^vI$=$Q6#O+pYX; SF0!}ouE?C&tj665bNe6q@f@!J literal 0 HcmV?d00001 diff --git a/utils.py b/utils.py new file mode 100644 index 0000000..7c64626 --- /dev/null +++ b/utils.py @@ -0,0 +1,53 @@ + +import requests +import json + + +def save_file(obj,id): + + + with open(f"User {id} .json", "w") as f: + json.dump(obj, f) + + +def make_api_call(): + + """make api call and get the user information + return: List - user info + """ + res = requests.get('http://jsonplaceholder.typicode.com/users') + result_obj = res.json() + return result_obj + +def clean_result(dct,id_number): + """clean up a result obj + return: dict - cleaned up version of the res obj. + """ + + + new_dct = { + "User_id": dct[id_number-1]['id'], + "Name": dct[id_number-1]['name'], + "Username": dct[id_number-1]['username'], + "Email": dct[id_number-1]['email'] + } + return new_dct + +def user_id(): + """a function to get random user + + Returns: + int: user's choice of user id + """ + print("Welcome to Userinfo App!") + + try: + user_id_number=int(input('"Please provide the input id you want the learn information: " (between 1 and 10)')) + assert 1<= user_id_number<=10 + + except ValueError: + print('Ooops that is not a valid input please try again...') + except AssertionError: + print("Please Enter a number between 1 and 10") + + return user_id_number \ No newline at end of file