Skip to content

Commit 346b0a8

Browse files
Rahul664rohanr18
andauthored
Added fetch_quotes.py (#6529)
* Added fetch_quotes.py fetches quotes from zenquotes.io api * Update web_programming/fetch_quotes.py Co-authored-by: rohanr18 <[email protected]> Co-authored-by: rohanr18 <[email protected]>
1 parent a12e694 commit 346b0a8

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Diff for: web_programming/fetch_quotes.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
This file fetches quotes from the " ZenQuotes API ".
3+
It does not require any API key as it uses free tier.
4+
5+
For more details and premium features visit:
6+
https://zenquotes.io/
7+
"""
8+
9+
import pprint
10+
11+
import requests
12+
13+
14+
def quote_of_the_day() -> list:
15+
API_ENDPOINT_URL = "https://zenquotes.io/api/today/"
16+
return requests.get(API_ENDPOINT_URL).json()
17+
18+
19+
def random_quotes() -> list:
20+
API_ENDPOINT_URL = "https://zenquotes.io/api/random/"
21+
return requests.get(API_ENDPOINT_URL).json()
22+
23+
24+
if __name__ == "__main__":
25+
"""
26+
response object has all the info with the quote
27+
To retrieve the actual quote access the response.json() object as below
28+
response.json() is a list of json object
29+
response.json()[0]['q'] = actual quote.
30+
response.json()[0]['a'] = author name.
31+
response.json()[0]['h'] = in html format.
32+
"""
33+
response = random_quotes()
34+
pprint.pprint(response)

0 commit comments

Comments
 (0)