Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1974f2b

Browse files
author
Rai Muhammad Haider
committed
API
1 parent 2f939a1 commit 1974f2b

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

‎APIHandling.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import requests
2+
# Get Rendom User
3+
def fetch_API():
4+
url = "https://api.freeapi.app/api/v1/public/randomusers/user/random"
5+
response = requests.get(url)
6+
data = response.json()
7+
8+
if data['success'] and 'data' in data:
9+
user_data = data['data']
10+
street_number = user_data['location']['street']['number']
11+
phone_number = user_data['phone']
12+
cell = user_data['cell']
13+
username = user_data['login']['username']
14+
email = user_data['email']
15+
country = user_data['location']['country']
16+
return username , email , country , cell , street_number, phone_number
17+
else:
18+
raise Exception('Fail to fetch User data ')
19+
20+
def main():
21+
try:
22+
username , email , country , cell , street_number , phone_number = fetch_API()
23+
print(f"Username : {username}\n Email : {email} \n Phone Number : {phone_number} \n Street Number : {street_number} ")
24+
except Exception as e:
25+
print(e)
26+
27+
if __name__ == '__main__':
28+
main()
29+
30+
# fetch_API()
31+
# Random Jocks ++++++++++++++++++++++++++++++
32+
import random
33+
def Jock_api():
34+
url = "https://api.freeapi.app/api/v1/public/randomjokes"
35+
response = requests.get(url)
36+
data = response.json()
37+
if data['success'] and 'data' in data:
38+
jock = data['data']['data']
39+
random_index = random.choice(jock)['content']
40+
return random_index
41+
else:
42+
raise Exception('Fail to fetch API')
43+
44+
def main_one():
45+
try:
46+
random_index = Jock_api()
47+
print(f"Random Jock :: {random_index}")
48+
except Exception as e:
49+
print(e)
50+
51+
if __name__ == "__main__":
52+
main_one()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /