StudyDaily / app.py
MonsterBoyTabs's picture
Update app.py
fc4345e verified
import streamlit as st
import json
from datetime import datetime
import calendar
import random
# Initialize session state
if 'tasks' not in st.session_state:
st.session_state.tasks = {
day: [] for day in ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
}
if 'streak' not in st.session_state:
st.session_state.streak = 0
# App title
st.title("πŸ“š Student Study Tracker")
days = list(st.session_state.tasks.keys())
# ========== Sidebar Features ==========
st.sidebar.header("πŸ—“οΈ Calendar")
current_date = datetime.now()
st.sidebar.markdown(f"### {current_date.strftime('%B %Y')}")
# Display the correct calendar for the current month and year
cal = calendar.monthcalendar(current_date.year, current_date.month)
calendar_text = ""
for week in cal:
week_str = " ".join(f"{day:2}" if day != 0 else " " for day in week)
calendar_text += week_str + "\n"
st.sidebar.text(calendar_text)
# Motivational Quotes
quotes = [
"The secret of getting ahead is getting started. – Mark Twain",
"You don’t have to be great to start, but you have to start to be great. – Zig Ziglar",
"The only way to do great work is to love what you do. – Steve Jobs"
]
st.sidebar.markdown("πŸ’¬ **Quote of the Day**")
st.sidebar.write(random.choice(quotes))
# Streak Counter
completed_days = sum(
1 for day in days
if any(task['checked'] for task in st.session_state.tasks[day])
)
st.sidebar.markdown(f"πŸ”₯ **Streak:** {completed_days}/7 days this week")
# ========== Main App ==========
# Progress Bar
total_tasks = sum(len(tasks) for tasks in st.session_state.tasks.values())
completed_tasks = sum(
sum(1 for task in st.session_state.tasks[day] if task['checked'])
for day in days
)
if total_tasks > 0:
st.progress(completed_tasks / total_tasks)
# Day Tabs
tabs = st.tabs(days)
for i, day in enumerate(days):
with tabs[i]:
# Display tasks
for task_idx, task in enumerate(st.session_state.tasks[day]):
checked = task['checked']
text = task['text']
tags = task.get('tags', [])
priority = task.get('priority', 'Medium')
col1, col2 = st.columns([0.8, 0.2])
with col1:
if checked:
st.markdown(
f"<div style='color: #888; text-decoration: line-through;'>"
f"πŸ“Œ {text} <small>(Priority: {priority}, Tags: {', '.join(tags)})</small>"
f"</div>",
unsafe_allow_html=True
)
else:
# Editable task details
new_text = st.text_input(
f"Task {task_idx + 1}",
value=text,
key=f"text_{day}_{task_idx}"
)
new_tags = st.multiselect(
"Tags",
options=["Study", "Homework", "Project", "Personal", "Assignment"], # Added "Assignment"
default=tags,
key=f"tags_{day}_{task_idx}"
)
new_priority = st.selectbox(
"Priority",
options=["High", "Medium", "Low"],
index=["High", "Medium", "Low"].index(priority),
key=f"priority_{day}_{task_idx}"
)
# Update task
st.session_state.tasks[day][task_idx]['text'] = new_text
st.session_state.tasks[day][task_idx]['tags'] = new_tags
st.session_state.tasks[day][task_idx]['priority'] = new_priority
with col2:
is_checked = st.checkbox(
"Done",
value=checked,
key=f"check_{day}_{task_idx}"
)
st.session_state.tasks[day][task_idx]['checked'] = is_checked
# Add new task button
if st.button(f"βž• Add Task for {day}"):
st.session_state.tasks[day].append({
'text': '',
'checked': False,
'tags': [],
'priority': 'Medium'
})
# Export Tasks
if st.button("πŸ“₯ Export Tasks"):
export_text = ""
for day in days:
export_text += f"### {day}\n"
for task in st.session_state.tasks[day]:
status = "βœ…" if task['checked'] else "❌"
export_text += f"- {status} {task['text']} (Priority: {task['priority']}, Tags: {', '.join(task['tags'])})\n"
export_text += "\n"
st.download_button(
label="Download Tasks",
data=export_text,
file_name="weekly_tasks.txt"
)
# Save all tasks
if st.button("πŸ’Ύ Save All Tasks"):
with open("tasks.json", "w") as f:
json.dump(st.session_state.tasks, f)
st.success("Progress saved!")