Skip to content

Commit c1df459

Browse files
committed
Add API handling script to fetch random user data and requirements file
1 parent 16bcd8e commit c1df459

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

Api_handling/Api_handling.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import requests
2+
3+
def fetch_random_user_freeapi():
4+
url = "https://api.freeapi.app/api/v1/public/randomusers/user/random"
5+
respone = requests.get(url)
6+
data = respone.json()
7+
8+
if data ["success"] and "data" in data:
9+
user_data = data["data"]
10+
user_name = user_data["login"] ["username"]
11+
country = user_data["location"] ["country"]
12+
return user_name,country
13+
else:
14+
raise Exception("Failed to fetch user data")
15+
16+
def main():
17+
try:
18+
user_name,country = fetch_random_user_freeapi()
19+
print(f"Username: {user_name}\ncountry:{country}")
20+
except Exception as e:
21+
print(str(e))
22+
23+
if __name__ == "__main__":
24+
main()
25+

Api_handling/requirements.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
certifi==2025.6.15
2+
charset-normalizer==3.4.2
3+
idna==3.10
4+
requests==2.32.4
5+
urllib3==2.5.0

0 commit comments

Comments
 (0)