Skip to content

Commit 565b165

Browse files
committed
[FEATURE] - Daily Affirmations Widget
Fixes #154
1 parent 708d554 commit 565b165

File tree

3 files changed

+202
-0
lines changed

3 files changed

+202
-0
lines changed
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
import streamlit as st
2+
import random
3+
import datetime
4+
import time
5+
import json
6+
from datetime import datetime, timedelta
7+
8+
class AffirmationWidget:
9+
def __init__(self):
10+
# Dictionary of affirmations by theme
11+
self.affirmations = {
12+
"confidence": [
13+
"I am capable of achieving anything I set my mind to.",
14+
"I trust my abilities and inner wisdom.",
15+
"I radiate confidence, self-respect, and inner harmony.",
16+
"I am worthy of respect and acceptance.",
17+
"My potential to succeed is infinite.",
18+
"I choose to be confident and self-assured.",
19+
"I am enough, just as I am."
20+
],
21+
"relaxation": [
22+
"I choose to feel calm and peaceful.",
23+
"I release all tension and embrace tranquility.",
24+
"I am surrounded by peaceful energy.",
25+
"My mind is calm, my body is relaxed.",
26+
"I breathe in peace and exhale stress.",
27+
"I deserve to rest and feel at peace.",
28+
"Tranquility flows through me with each breath."
29+
],
30+
"productivity": [
31+
"I am focused and productive in all I do.",
32+
"I complete my tasks efficiently and effectively.",
33+
"I use my time wisely and purposefully.",
34+
"I am motivated and driven to achieve my goals.",
35+
"I take action towards my dreams.",
36+
"I am organized and accomplish my priorities.",
37+
"My productivity increases each day."
38+
]
39+
}
40+
41+
def get_affirmation(self, theme):
42+
"""Get a random affirmation from the selected theme"""
43+
return random.choice(self.affirmations[theme])
44+
45+
def display_affirmation_widget():
46+
st.markdown("""
47+
<style>
48+
.affirmation-container {
49+
padding: 20px;
50+
border-radius: 10px;
51+
background-color: #f0f8ff;
52+
margin: 10px 0;
53+
text-align: center;
54+
}
55+
.affirmation-text {
56+
font-size: 24px;
57+
color: #2c3e50;
58+
font-weight: bold;
59+
margin: 20px 0;
60+
}
61+
.theme-selector {
62+
margin: 20px 0;
63+
}
64+
.refresh-interval {
65+
margin: 20px 0;
66+
}
67+
</style>
68+
""", unsafe_allow_html=True)
69+
70+
st.markdown("## 🌟 Daily Affirmations")
71+
72+
# Initialize the widget
73+
if 'affirmation_widget' not in st.session_state:
74+
st.session_state.affirmation_widget = AffirmationWidget()
75+
76+
# Initialize last update time
77+
if 'last_update' not in st.session_state:
78+
st.session_state.last_update = datetime.now()
79+
80+
# Theme selection
81+
theme = st.selectbox(
82+
"Choose your affirmation theme:",
83+
["confidence", "relaxation", "productivity"],
84+
key="theme_selector"
85+
)
86+
87+
# Refresh interval selection
88+
refresh_interval = st.slider(
89+
"Select refresh interval (minutes):",
90+
min_value=1,
91+
max_value=60,
92+
value=5,
93+
key="refresh_interval"
94+
)
95+
96+
# Enable notifications
97+
notifications_enabled = st.checkbox("Enable push notifications", value=False)
98+
99+
# Get current affirmation
100+
if 'current_affirmation' not in st.session_state:
101+
st.session_state.current_affirmation = st.session_state.affirmation_widget.get_affirmation(theme)
102+
103+
# Check if it's time to refresh
104+
current_time = datetime.now()
105+
time_difference = current_time - st.session_state.last_update
106+
if time_difference.total_seconds() >= (refresh_interval * 60):
107+
st.session_state.current_affirmation = st.session_state.affirmation_widget.get_affirmation(theme)
108+
st.session_state.last_update = current_time
109+
110+
# Display affirmation
111+
st.markdown(
112+
f"""
113+
<div class="affirmation-container">
114+
<div class="affirmation-text">
115+
"{st.session_state.current_affirmation}"
116+
</div>
117+
</div>
118+
""",
119+
unsafe_allow_html=True
120+
)
121+
122+
# Manual refresh button
123+
if st.button("↻ New Affirmation"):
124+
st.session_state.current_affirmation = st.session_state.affirmation_widget.get_affirmation(theme)
125+
st.session_state.last_update = current_time
126+
127+
# Display last update time
128+
st.markdown(
129+
f"<div style='text-align: center; color: #666;'>Last updated: {st.session_state.last_update.strftime('%I:%M %p')}</div>",
130+
unsafe_allow_html=True
131+
)
132+
133+
# Save preferences
134+
if st.button("Save Preferences"):
135+
preferences = {
136+
"theme": theme,
137+
"refresh_interval": refresh_interval,
138+
"notifications_enabled": notifications_enabled
139+
}
140+
st.success("Preferences saved successfully!")
141+
142+
# To use this widget in your Streamlit app:
143+
if __name__ == "__main__":
144+
display_affirmation_widget()
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Core dependencies
2+
streamlit>=1.28.0
3+
pandas>=2.0.0
4+
numpy>=1.24.0
5+
6+
# DateTime handling
7+
python-dateutil>=2.8.2
8+
pytz>=2023.3
9+
10+
# Database
11+
pymongo>=4.5.0
12+
13+
# HTTP requests and API handling
14+
requests>=2.31.0
15+
anthropic>=0.3.0
16+
17+
# UI components
18+
streamlit-option-menu>=0.3.2
19+
streamlit-lottie>=0.0.5
20+
21+
# Audio/Media handling
22+
playsound>=1.3.0
23+
24+
# Security and encryption
25+
python-dotenv>=1.0.0
26+
cryptography>=41.0.0
27+
28+
# Notifications (if implementing push notifications)
29+
firebase-admin>=6.2.0
30+
pywebpush>=1.14.0
31+
32+
# Image processing
33+
Pillow>=10.0.0
34+
35+
# Data visualization
36+
plotly>=5.18.0
37+
38+
# Logging and monitoring
39+
logging>=0.5.1.2
40+
41+
# State management
42+
cachetools>=5.3.0
43+
44+
# JSON handling
45+
jsonschema>=4.19.0
46+
47+
# For development and testing
48+
pytest>=7.4.0
49+
black>=23.9.0
50+
flake8>=6.1.0
51+
52+
# Version control
53+
setuptools>=68.0.0
54+
wheel>=0.41.0

app.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from dotenv import load_dotenv
1818
import logging
1919
import sys
20+
from affirmation_widget import display_affirmation_widget
2021

2122

2223
# Configure logging
@@ -818,6 +819,9 @@ def simon_game_challenge():
818819
def show_calm_space():
819820
st.title("Calm Space")
820821
st.write("Engage in a breathing exercise to calm your mind.")
822+
823+
st.subheader("Daily Affirmations")
824+
display_affirmation_widget()
821825

822826
st.subheader("Quick Tips for Positivity")
823827
quick_tips = [

0 commit comments

Comments
 (0)