From c018e794fa1527ecebeb78ec888dcd1b04560c09 Mon Sep 17 00:00:00 2001 From: kom-senapati Date: Sun, 7 Jul 2024 08:06:21 +0530 Subject: [PATCH 1/2] =?UTF-8?q?code:=20world=20clock=20=E2=9C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pages/programs/ApiPrograms/worldClock.py | 36 +++++++++++++++++++ src/apps/pages/programs/apiProgram.py | 5 ++- 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/apps/pages/programs/ApiPrograms/worldClock.py diff --git a/src/apps/pages/programs/ApiPrograms/worldClock.py b/src/apps/pages/programs/ApiPrograms/worldClock.py new file mode 100644 index 00000000..4afdd86f --- /dev/null +++ b/src/apps/pages/programs/ApiPrograms/worldClock.py @@ -0,0 +1,36 @@ +from datetime import datetime +import pytz +import streamlit as st +import time + +def get_city_time(timezone): + tz = pytz.timezone(timezone) + city_time = datetime.now(tz) + return city_time.strftime('%H:%M:%S'), city_time.strftime('%A, %Y-%m-%d') + +def display_world_clock(): + st.title("World Clock") + + cities = { + "New York": "America/New_York", + "London": "Europe/London", + "Tokyo": "Asia/Tokyo", + "Sydney": "Australia/Sydney", + "Delhi": "Asia/Kolkata", + "Paris": "Europe/Paris" + } + + selected_city = st.selectbox("Select a city", list(cities.keys())) + + if selected_city: + time_placeholder = st.empty() + date_placeholder = st.empty() + + while True: + city_time, city_date = get_city_time(cities[selected_city]) + time_placeholder.markdown(f"# {city_time}") + date_placeholder.markdown(f"## {city_date}") + time.sleep(1) + +if __name__ == "__main__": + display_world_clock() diff --git a/src/apps/pages/programs/apiProgram.py b/src/apps/pages/programs/apiProgram.py index cbb6b105..27797058 100644 --- a/src/apps/pages/programs/apiProgram.py +++ b/src/apps/pages/programs/apiProgram.py @@ -2,7 +2,7 @@ def apiPrograms(): st.title('API Programs') - choice = st.selectbox('Select a program to execute', [None, "Jokes", "General Facts", "Gemini ChatBot"]) + choice = st.selectbox('Select a program to execute', [None, "Jokes", "General Facts", "Gemini ChatBot", "World Clock"]) st.markdown('---') if choice == "Jokes": from src.apps.pages.programs.ApiPrograms.joke import play_joke @@ -13,6 +13,9 @@ def apiPrograms(): elif choice == "Gemini ChatBot": from src.apps.pages.programs.ApiPrograms.genAIChatbot import chatBot chatBot() + elif choice == "World Clock": + from src.apps.pages.programs.ApiPrograms.worldClock import display_world_clock + display_world_clock() else: st.info("Star this project on [GitHub](https://github.com/Avdhesh-Varshney/Jarvis), if you like it!", icon='⭐') From a1ec2e309b325489a5de52c62343e311c861f831 Mon Sep 17 00:00:00 2001 From: kom-senapati Date: Sun, 7 Jul 2024 08:11:16 +0530 Subject: [PATCH 2/2] chore: refactor world clock -> simple program --- .../programs/{ApiPrograms => SimplePrograms}/worldClock.py | 0 src/apps/pages/programs/apiProgram.py | 5 +---- src/apps/pages/programs/simpleProgram.py | 5 ++++- 3 files changed, 5 insertions(+), 5 deletions(-) rename src/apps/pages/programs/{ApiPrograms => SimplePrograms}/worldClock.py (100%) diff --git a/src/apps/pages/programs/ApiPrograms/worldClock.py b/src/apps/pages/programs/SimplePrograms/worldClock.py similarity index 100% rename from src/apps/pages/programs/ApiPrograms/worldClock.py rename to src/apps/pages/programs/SimplePrograms/worldClock.py diff --git a/src/apps/pages/programs/apiProgram.py b/src/apps/pages/programs/apiProgram.py index 27797058..cbb6b105 100644 --- a/src/apps/pages/programs/apiProgram.py +++ b/src/apps/pages/programs/apiProgram.py @@ -2,7 +2,7 @@ def apiPrograms(): st.title('API Programs') - choice = st.selectbox('Select a program to execute', [None, "Jokes", "General Facts", "Gemini ChatBot", "World Clock"]) + choice = st.selectbox('Select a program to execute', [None, "Jokes", "General Facts", "Gemini ChatBot"]) st.markdown('---') if choice == "Jokes": from src.apps.pages.programs.ApiPrograms.joke import play_joke @@ -13,9 +13,6 @@ def apiPrograms(): elif choice == "Gemini ChatBot": from src.apps.pages.programs.ApiPrograms.genAIChatbot import chatBot chatBot() - elif choice == "World Clock": - from src.apps.pages.programs.ApiPrograms.worldClock import display_world_clock - display_world_clock() else: st.info("Star this project on [GitHub](https://github.com/Avdhesh-Varshney/Jarvis), if you like it!", icon='⭐') diff --git a/src/apps/pages/programs/simpleProgram.py b/src/apps/pages/programs/simpleProgram.py index 24019e02..5d5125c4 100644 --- a/src/apps/pages/programs/simpleProgram.py +++ b/src/apps/pages/programs/simpleProgram.py @@ -2,7 +2,7 @@ def simplePrograms(): st.title('Simple Programs') - choice = st.selectbox('Select a program to execute', [None, 'Timer', 'Password Generator','Caeser Cipher']) + choice = st.selectbox('Select a program to execute', [None, 'Timer', 'Password Generator','Caeser Cipher', 'World Clock']) st.markdown('---') @@ -15,6 +15,9 @@ def simplePrograms(): elif choice == 'Caeser Cipher': from src.apps.pages.programs.SimplePrograms.CaeserCipher import caeserCipher caeserCipher() + elif choice == 'World Clock': + from src.apps.pages.programs.SimplePrograms.worldClock import display_world_clock + display_world_clock() else: st.info("Star this project on [GitHub](https://github.com/Avdhesh-Varshney/Jarvis), if you like it!", icon='⭐')