From 6aeebcd2c1b158e8bbfb2faac4498db6757b35d2 Mon Sep 17 00:00:00 2001 From: Pavan Bhat <363pavanbhat@gmail.com> Date: Mon, 14 Feb 2022 13:47:21 +0530 Subject: [PATCH] random-quote-generator --- RandomQuoteGenerator/README.md | 7 +++++++ RandomQuoteGenerator/random-quote.py | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 RandomQuoteGenerator/README.md create mode 100644 RandomQuoteGenerator/random-quote.py diff --git a/RandomQuoteGenerator/README.md b/RandomQuoteGenerator/README.md new file mode 100644 index 00000000..756abfe1 --- /dev/null +++ b/RandomQuoteGenerator/README.md @@ -0,0 +1,7 @@ + Packages Used + +``` +pip install requests +``` + +API used : Quote Garden \ No newline at end of file diff --git a/RandomQuoteGenerator/random-quote.py b/RandomQuoteGenerator/random-quote.py new file mode 100644 index 00000000..adbd1cf3 --- /dev/null +++ b/RandomQuoteGenerator/random-quote.py @@ -0,0 +1,22 @@ +import requests + + +## function that gets the random quote +def get_random_quote(): + try: + ## making the get request + response = requests.get("https://quote-garden.herokuapp.com/api/v3/quotes/random") + if response.status_code == 200: + ## extracting the core data + json_data = response.json() + data = json_data['data'] + + ## getting the quote from the data + print(data[0]['quoteText']) + else: + print("Error while getting quote") + except: + print("Something went wrong! Try Again!") + + +get_random_quote()