File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change
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 } \n country:{ country } " )
20
+ except Exception as e :
21
+ print (str (e ))
22
+
23
+ if __name__ == "__main__" :
24
+ main ()
25
+
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments