From 3c009a8cb3a1416c600c9f541fc6fe9cc37a6a5f Mon Sep 17 00:00:00 2001 From: Akarsh Ghildyal Date: Sun, 7 Jul 2024 11:32:45 +0530 Subject: [PATCH] feat : quote of the day --- src/apps/pages/programs/ApiPrograms/quotes.py | 20 +++++++++++++++++++ src/apps/pages/programs/apiProgram.py | 5 ++++- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 src/apps/pages/programs/ApiPrograms/quotes.py diff --git a/src/apps/pages/programs/ApiPrograms/quotes.py b/src/apps/pages/programs/ApiPrograms/quotes.py new file mode 100644 index 00000000..4c1715df --- /dev/null +++ b/src/apps/pages/programs/ApiPrograms/quotes.py @@ -0,0 +1,20 @@ +import streamlit as st +import requests + +def show_quote(): + def get_quote(): + response = requests.get("https://zenquotes.io/api/today") + if response.status_code == 200: + return response.json()[0] + else: + return None + + st.title("Quote of the Day") + + quote = get_quote() + box = st.empty() + if quote: + text = f"**{quote['q']}**\n\n— {quote['a']}" + box.markdown(text) + else: + st.write("Couldn't fetch a quote at this moment. Please try again later.") diff --git a/src/apps/pages/programs/apiProgram.py b/src/apps/pages/programs/apiProgram.py index 707194c4..1a8fd6b6 100644 --- a/src/apps/pages/programs/apiProgram.py +++ b/src/apps/pages/programs/apiProgram.py @@ -2,11 +2,14 @@ def apiPrograms(): st.title('API Programs') - choice = st.selectbox('Select a program to execute', [None, "Jokes"]) + choice = st.selectbox('Select a program to execute', [None, "Jokes", "Quote of the Day"]) st.markdown('---') if choice == "Jokes": from src.apps.pages.programs.ApiPrograms.joke import play_joke play_joke() + elif choice == "Quote of the Day": + from src.apps.pages.programs.ApiPrograms.quotes import show_quote + show_quote() else: st.info("Star this project on [GitHub](https://github.com/Avdhesh-Varshney/Jarvis), if you like it!", icon='⭐')