-
Notifications
You must be signed in to change notification settings - Fork 1
/
api.py
92 lines (86 loc) · 1.71 KB
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import requests
# List of categories
categories = [
"age",
"alone",
"amazing",
"anger",
"architecture",
"art",
"attitude",
"beauty",
"best",
"birthday",
"business",
"car",
"change",
"communication",
"computers",
"cool",
"courage",
"dad",
"dating",
"death",
"design",
"dreams",
"education",
"environmental",
"equality",
"experience",
"failure",
"faith",
"family",
"famous",
"fear",
"fitness",
"food",
"forgiveness",
"freedom",
"friendship",
"funny",
"future",
"god",
"good",
"government",
"graduation",
"great",
"happiness",
"health",
"history",
"home",
"hope",
"humor",
"imagination",
"inspirational",
"intelligence",
"jealousy",
"knowledge",
"leadership",
"learning",
"legal",
"life",
"love",
"marriage",
"medical",
"men",
"mom",
"money",
"morning",
"movies",
"success",
]
# Print the categories
print("Available categories:")
for category in categories:
print("-", category)
# Prompt the user to enter the category of quotes
category = input("Enter the category of from the above : ")
# Construct the API URL with the user-provided category
api_url = 'https://api.api-ninjas.com/v1/quotes?category={}'.format(category)
# Replace 'YOUR_API_KEY' with your actual API key
response = requests.get(api_url, headers={'X-Api-Key': 'YOUR_API_KEY'})
# Check if the request was successful
if response.status_code == requests.codes.ok:
print(response.text) # Print the response (quote)
else:
print("Error:", response.status_code, response.text) # Print error message