Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Alarm program #105

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions src/apps/pages/programs/SimplePrograms/alarm_program.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import streamlit as st
import datetime
import time
# Function to check the alarm and notify
def check_alarm():
alarm_time = st.session_state.alarm_time
snooze_time = st.session_state.snooze_time
alarm_message = st.session_state.alarm_message
alarm_note = st.session_state.alarm_note
while True:
# Get current time
current_time = datetime.datetime.now().strftime("%H:%M:%S")
# Check if the alarm time matches the current time
if current_time == alarm_time:
st.session_state.alarm_triggered = True
st.session_state.alarm_message = alarm_message
st.session_state.alarm_note = alarm_note
break
# Check if snooze time is set and if it's time to trigger snooze
if st.session_state.snooze_triggered:
snooze_alarm_time = (datetime.datetime.now() + datetime.timedelta(minutes=snooze_time)).strftime("%H:%M:%S")
if current_time == snooze_alarm_time:
st.session_state.alarm_triggered = True
st.session_state.alarm_message = alarm_message
st.session_state.alarm_note = alarm_note
st.session_state.snooze_triggered = False
break
# Wait for one second
time.sleep(1)
# Streamlit app code
def Alarm_App():
st.title("Alarm Clock")
# Initialize session state
if 'alarm_triggered' not in st.session_state:
st.session_state.alarm_triggered = False
if 'snooze_triggered' not in st.session_state:
st.session_state.snooze_triggered = False
if 'snooze_time' not in st.session_state:
st.session_state.snooze_time = 0
# Input for hour, minute, and second
hour = st.selectbox("Hour", list(range(24)), format_func=lambda x: f"{x:02d}")
minute = st.selectbox("Minute", list(range(60)), format_func=lambda x: f"{x:02d}")
second = st.selectbox("Second", list(range(60)), format_func=lambda x: f"{x:02d}")
# Create alarm time
alarm_time = f"{hour:02d}:{minute:02d}:{second:02d}"
# Message options
message_option = st.radio(
"Choose Alarm Message Option",
("None", "Custom Message", "Predefined Message")
)
if message_option == "Custom Message":
alarm_message = st.text_input("Enter your custom message", "Time's up!")
elif message_option == "Predefined Message":
predefined_messages = ["Wake up!", "Meeting time!", "Take a break!"]
alarm_message = st.selectbox("Choose a predefined message", predefined_messages)
else:
alarm_message = "Time's up!"
# Note/Link options
note_option = st.radio(
"Choose Note/Link Option",
("None", "Custom Note/Link")
)
if note_option == "Custom Note/Link":
alarm_note = st.text_area("Enter your link or note here", "")
else:
alarm_note = "No note or link"
# Snooze functionality
snooze_time = st.number_input("Snooze Time (minutes)", min_value=0, max_value=60, value=0)
# Set alarm button
if st.button("Set Alarm"):
st.session_state.alarm_time = alarm_time
st.session_state.alarm_message = alarm_message
st.session_state.alarm_note = alarm_note
st.session_state.snooze_time = snooze_time
st.session_state.snooze_triggered = False
st.success(f"Alarm set for {alarm_time} with message: '{alarm_message}' and note: '{alarm_note}'")
check_alarm()
# Display alarm notification if triggered
if st.session_state.alarm_triggered:
st.balloons()
st.warning(st.session_state.alarm_message)
st.info(f"Note/Link: {st.session_state.alarm_note}")
st.session_state.alarm_triggered = False
6 changes: 5 additions & 1 deletion src/apps/pages/programs/simpleProgram.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

def simplePrograms():
st.title('Simple Programs')
choice = st.selectbox('Select a program to execute', [None, 'Timer', 'Password Generator','Caeser Cipher', 'Calculator', 'World Clock', 'Internet Speed Test'])
choice = st.selectbox('Select a program to execute', [None, 'Timer', 'Password Generator','Caeser Cipher', 'Calculator', 'World Clock', 'Internet Speed Test',"Alarm Program"])

st.markdown('---')

Expand All @@ -24,6 +24,10 @@ def simplePrograms():
elif choice == 'Internet Speed Test':
from src.apps.pages.programs.SimplePrograms.Internet_Speed_Test import Internet_Speed_Test
Internet_Speed_Test()
elif choice == 'Alarm Program':
from src.apps.pages.programs.SimplePrograms.alarm_program import Alarm_App
Alarm_App()

else:
st.info("Star this project on [GitHub](https://github.com/Avdhesh-Varshney/Jarvis), if you like it!", icon='⭐')

Expand Down