Update app.py
Browse files
app.py
CHANGED
|
@@ -1,237 +1,236 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
from datetime import datetime, timedelta, time
|
| 3 |
-
import calendar
|
| 4 |
-
import pandas as pd
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
df
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
)
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
"
|
| 47 |
-
"
|
| 48 |
-
"
|
| 49 |
-
"
|
| 50 |
-
"
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
st.
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
st.
|
| 61 |
-
task_df =
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
st.
|
| 69 |
-
|
| 70 |
-
f"
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
st.
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
st.
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
st.write(f"**
|
| 90 |
-
st.write(f"**
|
| 91 |
-
st.write(f"**Due
|
| 92 |
-
st.write(f"**
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
today
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
df
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
background-
|
| 127 |
-
background-
|
| 128 |
-
background-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
background-
|
| 135 |
-
background-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
st.sidebar.
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
st.sidebar.markdown("
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
col1
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
"
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
"
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
"
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
if __name__ == "__main__":
|
| 237 |
main()
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from datetime import datetime, timedelta, time
|
| 3 |
+
import calendar
|
| 4 |
+
import pandas as pd
|
| 5 |
+
# Helper function to render the calendar for the selected month
|
| 6 |
+
def render_calendar(month, year):
|
| 7 |
+
st.write(f"### {calendar.month_name[month]} {year}")
|
| 8 |
+
weekdays = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
|
| 9 |
+
month_days = calendar.monthcalendar(year, month)
|
| 10 |
+
|
| 11 |
+
table = []
|
| 12 |
+
for week in month_days:
|
| 13 |
+
row = []
|
| 14 |
+
for day in week:
|
| 15 |
+
row.append(day if day != 0 else "")
|
| 16 |
+
table.append(row)
|
| 17 |
+
|
| 18 |
+
df = pd.DataFrame(table, columns=weekdays)
|
| 19 |
+
return df
|
| 20 |
+
|
| 21 |
+
# Display and interact with the tasks for a selected date
|
| 22 |
+
def log_task_for_date(selected_date):
|
| 23 |
+
if selected_date not in st.session_state:
|
| 24 |
+
st.session_state[selected_date] = []
|
| 25 |
+
|
| 26 |
+
st.write(f"### Tasks for {selected_date}")
|
| 27 |
+
|
| 28 |
+
task = st.text_input("Enter a task", key=f"task_input_{selected_date}")
|
| 29 |
+
category = st.selectbox("Select Category", ["Work", "Personal", "Urgent", "Other"], key=f"category_select_{selected_date}")
|
| 30 |
+
priority = st.selectbox("Select Priority", ["High", "Medium", "Low"], key=f"priority_select_{selected_date}")
|
| 31 |
+
due_date = st.date_input("Select Due Date", min_value=datetime.today(), key=f"due_date_input_{selected_date}")
|
| 32 |
+
|
| 33 |
+
# Custom time selection with 24-hour dropdown
|
| 34 |
+
time_options = [time(hour=h, minute=m).strftime("%H:%M") for h in range(24) for m in (0, 30)]
|
| 35 |
+
selected_time_str = st.selectbox(
|
| 36 |
+
"Select Due Time",
|
| 37 |
+
options=time_options,
|
| 38 |
+
index=time_options.index("09:00"),
|
| 39 |
+
key=f"due_time_input_{selected_date}"
|
| 40 |
+
)
|
| 41 |
+
due_time = datetime.strptime(selected_time_str, "%H:%M").time()
|
| 42 |
+
|
| 43 |
+
if st.button("Add Task", key=f"add_task_button_{selected_date}"):
|
| 44 |
+
task_info = {
|
| 45 |
+
"task": task,
|
| 46 |
+
"category": category,
|
| 47 |
+
"priority": priority,
|
| 48 |
+
"due_date": str(due_date),
|
| 49 |
+
"due_time": str(due_time),
|
| 50 |
+
"completed": False,
|
| 51 |
+
}
|
| 52 |
+
if task_info not in st.session_state[selected_date]:
|
| 53 |
+
st.session_state[selected_date].append(task_info)
|
| 54 |
+
st.success("Task added!")
|
| 55 |
+
else:
|
| 56 |
+
st.warning("Task already exists!")
|
| 57 |
+
|
| 58 |
+
if st.session_state[selected_date]:
|
| 59 |
+
st.write("**Current Tasks:**")
|
| 60 |
+
task_df = pd.DataFrame(st.session_state[selected_date])
|
| 61 |
+
task_df = task_df.sort_values(by=["priority", "due_date", "due_time"], ascending=[True, True, True])
|
| 62 |
+
|
| 63 |
+
for idx, row in task_df.iterrows():
|
| 64 |
+
task_str = f"{row['task']} - Category: {row['category']} | Priority: {row['priority']} | Due: {row['due_date']} {row['due_time']}"
|
| 65 |
+
if row['completed']:
|
| 66 |
+
task_str = f"β
{task_str}"
|
| 67 |
+
st.write(task_str)
|
| 68 |
+
mark_as_completed = st.checkbox(
|
| 69 |
+
f"Mark as completed",
|
| 70 |
+
key=f"complete_{selected_date}_{idx}",
|
| 71 |
+
value=row['completed']
|
| 72 |
+
)
|
| 73 |
+
if mark_as_completed and not row['completed']:
|
| 74 |
+
st.session_state[selected_date][idx]["completed"] = True
|
| 75 |
+
st.success(f"Task '{row['task']}' marked as completed!")
|
| 76 |
+
|
| 77 |
+
# Search and view tasks by date without needing to type
|
| 78 |
+
def view_tasks_by_date():
|
| 79 |
+
st.write("## π View Tasks by Date")
|
| 80 |
+
selected = st.date_input("Pick a Date to View Tasks", value=datetime.today())
|
| 81 |
+
selected_str = str(selected)
|
| 82 |
+
tasks = st.session_state.get(selected_str, [])
|
| 83 |
+
|
| 84 |
+
if tasks:
|
| 85 |
+
st.write(f"### Tasks for {selected_str}")
|
| 86 |
+
for idx, task in enumerate(tasks):
|
| 87 |
+
with st.expander(f"{'β
' if task['completed'] else ''}{task['task']}"):
|
| 88 |
+
st.write(f"**Category:** {task['category']}")
|
| 89 |
+
st.write(f"**Priority:** {task['priority']}")
|
| 90 |
+
st.write(f"**Due Date:** {task['due_date']}")
|
| 91 |
+
st.write(f"**Due Time:** {task['due_time']}")
|
| 92 |
+
st.write(f"**Completed:** {'Yes β
' if task['completed'] else 'No β'}")
|
| 93 |
+
else:
|
| 94 |
+
st.info("No tasks logged for this date.")
|
| 95 |
+
|
| 96 |
+
# Highlight today's date
|
| 97 |
+
def highlight_today(month, year):
|
| 98 |
+
today = datetime.today()
|
| 99 |
+
if today.month == month and today.year == year:
|
| 100 |
+
return today.day
|
| 101 |
+
return None
|
| 102 |
+
|
| 103 |
+
# Generate CSV data for tasks
|
| 104 |
+
def get_task_csv(scope, selected_date):
|
| 105 |
+
tasks = []
|
| 106 |
+
for date, task_list in st.session_state.items():
|
| 107 |
+
if isinstance(task_list, list):
|
| 108 |
+
if scope == "day" and date == selected_date:
|
| 109 |
+
tasks.extend(task_list)
|
| 110 |
+
elif scope == "month" and date.startswith(selected_date[:7]):
|
| 111 |
+
tasks.extend(task_list)
|
| 112 |
+
elif scope == "year" and date.startswith(selected_date[:4]):
|
| 113 |
+
tasks.extend(task_list)
|
| 114 |
+
df = pd.DataFrame(tasks)
|
| 115 |
+
return df.to_csv(index=False)
|
| 116 |
+
|
| 117 |
+
# Main Streamlit app with sidebar
|
| 118 |
+
def main():
|
| 119 |
+
# Apply custom CSS to set light grey background
|
| 120 |
+
st.markdown(
|
| 121 |
+
"""
|
| 122 |
+
<style>
|
| 123 |
+
/* Main background */
|
| 124 |
+
[data-testid="stAppViewContainer"] {
|
| 125 |
+
background-image: url('https://png.pngtree.com/thumb_back/fh260/background/20240916/pngtree-simple-orange-aesthetic-background-image_16213466.jpg');
|
| 126 |
+
background-size: cover;
|
| 127 |
+
background-position: center;
|
| 128 |
+
background-repeat: no-repeat;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
/* Sidebar background */
|
| 132 |
+
[data-testid="stSidebar"] > div:first-child {
|
| 133 |
+
background-image: url('https://st.depositphotos.com/2890321/51451/i/600/depositphotos_514519944-stock-photo-close-calendar-purple-table-background.jpg');
|
| 134 |
+
background-size: cover;
|
| 135 |
+
background-position: center;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
/* Optional: semi-transparent overlay for content readability */
|
| 139 |
+
.main > div {
|
| 140 |
+
background-color: rgba(255, 255, 255, 0.85);
|
| 141 |
+
padding: 1rem;
|
| 142 |
+
border-radius: 12px;
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
/* Styling sidebar links */
|
| 146 |
+
.sidebar-links img {
|
| 147 |
+
width: 20px;
|
| 148 |
+
margin-right: 10px;
|
| 149 |
+
vertical-align: middle;
|
| 150 |
+
}
|
| 151 |
+
.sidebar-links a {
|
| 152 |
+
text-decoration: none;
|
| 153 |
+
display: inline-block;
|
| 154 |
+
color: white;
|
| 155 |
+
font-weight: bold;
|
| 156 |
+
margin-bottom: 8px;
|
| 157 |
+
}
|
| 158 |
+
</style>
|
| 159 |
+
""",
|
| 160 |
+
unsafe_allow_html=True
|
| 161 |
+
)
|
| 162 |
+
|
| 163 |
+
st.title("π
Dynamic Calendar & Task Logger")
|
| 164 |
+
|
| 165 |
+
# Sidebar for navigation
|
| 166 |
+
st.sidebar.title("Navigation")
|
| 167 |
+
app_mode = st.sidebar.radio("Choose an Option", ("Log Tasks", "View Tasks", "Download Task Data"))
|
| 168 |
+
|
| 169 |
+
# Connect with Me Section
|
| 170 |
+
st.sidebar.markdown("## π¨βπ» Connect with Me")
|
| 171 |
+
st.sidebar.markdown("""
|
| 172 |
+
<div class="sidebar-links">
|
| 173 |
+
<a href="https://github.com/marianadeem755" target="_blank">
|
| 174 |
+
<img src="https://cdn-icons-png.flaticon.com/512/25/25231.png"> GitHub
|
| 175 |
+
</a><br>
|
| 176 |
+
<a href="https://www.kaggle.com/marianadeem755" target="_blank">
|
| 177 |
+
<img src="https://cdn4.iconfinder.com/data/icons/logos-and-brands/512/189_Kaggle_logo_logos-512.png"> Kaggle
|
| 178 |
+
</a><br>
|
| 179 |
+
<a href="mailto:marianadeem755@gmail.com">
|
| 180 |
+
<img src="https://cdn-icons-png.flaticon.com/512/561/561127.png"> Email
|
| 181 |
+
</a><br>
|
| 182 |
+
<a href="https://huggingface.co/maria355" target="_blank">
|
| 183 |
+
<img src="https://huggingface.co/front/assets/huggingface_logo-noborder.svg"> Hugging Face
|
| 184 |
+
</a>
|
| 185 |
+
</div>
|
| 186 |
+
""", unsafe_allow_html=True)
|
| 187 |
+
|
| 188 |
+
if "initialized" not in st.session_state:
|
| 189 |
+
st.session_state.initialized = True
|
| 190 |
+
|
| 191 |
+
today = datetime.today()
|
| 192 |
+
month = st.selectbox("Select Month", list(range(1, 13)), index=today.month - 1)
|
| 193 |
+
year = st.selectbox("Select Year", list(range(today.year - 5, today.year + 6)), index=5)
|
| 194 |
+
|
| 195 |
+
calendar_df = render_calendar(month, year)
|
| 196 |
+
today_day = highlight_today(month, year)
|
| 197 |
+
|
| 198 |
+
for col in calendar_df.columns:
|
| 199 |
+
calendar_df[col] = calendar_df[col].apply(lambda x: f"**{x}**" if x == today_day else x)
|
| 200 |
+
|
| 201 |
+
st.table(calendar_df)
|
| 202 |
+
|
| 203 |
+
selected_date = st.date_input("Select a Date to Add Tasks", today)
|
| 204 |
+
|
| 205 |
+
if app_mode == "Log Tasks":
|
| 206 |
+
log_task_for_date(str(selected_date))
|
| 207 |
+
|
| 208 |
+
elif app_mode == "View Tasks":
|
| 209 |
+
view_tasks_by_date()
|
| 210 |
+
|
| 211 |
+
elif app_mode == "Download Task Data":
|
| 212 |
+
col1, col2, col3 = st.columns(3)
|
| 213 |
+
with col1:
|
| 214 |
+
st.download_button(
|
| 215 |
+
"Download for Day π
",
|
| 216 |
+
data=get_task_csv("day", str(selected_date)),
|
| 217 |
+
file_name=f"tasks_day_{selected_date}.csv",
|
| 218 |
+
mime="text/csv"
|
| 219 |
+
)
|
| 220 |
+
with col2:
|
| 221 |
+
st.download_button(
|
| 222 |
+
"Download for Month ποΈ",
|
| 223 |
+
data=get_task_csv("month", str(selected_date)),
|
| 224 |
+
file_name=f"tasks_month_{selected_date.strftime('%Y-%m')}.csv",
|
| 225 |
+
mime="text/csv"
|
| 226 |
+
)
|
| 227 |
+
with col3:
|
| 228 |
+
st.download_button(
|
| 229 |
+
"Download for Year π",
|
| 230 |
+
data=get_task_csv("year", str(selected_date)),
|
| 231 |
+
file_name=f"tasks_year_{selected_date.strftime('%Y')}.csv",
|
| 232 |
+
mime="text/csv"
|
| 233 |
+
)
|
| 234 |
+
|
| 235 |
+
if __name__ == "__main__":
|
|
|
|
| 236 |
main()
|