From fb02d8ba0dc99e30f79ba437dd8e26dc508795f0 Mon Sep 17 00:00:00 2001 From: RAHUL S H Date: Sun, 2 Oct 2022 00:03:06 -0700 Subject: [PATCH 1/2] Added fetch_quotes.py fetches quotes from zenquotes.io api --- web_programming/fetch_quotes.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 web_programming/fetch_quotes.py diff --git a/web_programming/fetch_quotes.py b/web_programming/fetch_quotes.py new file mode 100644 index 000000000000..c0b6c762605c --- /dev/null +++ b/web_programming/fetch_quotes.py @@ -0,0 +1,33 @@ +""" +This file fetches quotes from the " ZenQuotes API ". +It does not require any API key as it uses free tier. + +For more details and premium features visit: + https://zenquotes.io/ +""" + +import requests +import pprint + + +def quote_of_the_day() -> list: + API_ENDPOINT_URL = "https://zenquotes.io/api/today/" + return requests.get(API_ENDPOINT_URL).json() + + +def random_quotes() -> list: + API_ENDPOINT_URL = "https://zenquotes.io/api/random/" + return requests.get(API_ENDPOINT_URL).json() + + +if __name__ == "__main__": + """ + response object has all the info with the quote + To retrieve the actual quote access the response.json() object as below + response.json() is a list of json object + response.json()[0]['q'] = actual quote. + response.json()[0]['a'] = author name. + response.json()[0]['h'] = in html format. + """ + response = random_quotes() + pprint.pprint(response) From ef4f4454f6be78469035d4fb85d2e1c19f3e9fd3 Mon Sep 17 00:00:00 2001 From: RAHUL S H Date: Sun, 2 Oct 2022 01:09:21 -0700 Subject: [PATCH 2/2] Update web_programming/fetch_quotes.py Co-authored-by: rohanr18 <114707091+rohanr18@users.noreply.github.com> --- web_programming/fetch_quotes.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/web_programming/fetch_quotes.py b/web_programming/fetch_quotes.py index c0b6c762605c..4a3b002e515f 100644 --- a/web_programming/fetch_quotes.py +++ b/web_programming/fetch_quotes.py @@ -6,9 +6,10 @@ https://zenquotes.io/ """ -import requests import pprint +import requests + def quote_of_the_day() -> list: API_ENDPOINT_URL = "https://zenquotes.io/api/today/"