Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,10 +9,6 @@ import os
|
|
| 9 |
st.set_page_config(page_title="Task Manager with Procrastination Alerts", page_icon="π")
|
| 10 |
st.title("π Task Manager with Procrastination Alerts")
|
| 11 |
|
| 12 |
-
# Temporary storage for user tasks
|
| 13 |
-
user_tasks = {}
|
| 14 |
-
user_preferences = {"name": "John Doe", "email": "john@gmail.com"}
|
| 15 |
-
|
| 16 |
# Logging setup
|
| 17 |
logging.basicConfig(level=logging.INFO)
|
| 18 |
|
|
@@ -36,7 +32,7 @@ def filter_tasks(section):
|
|
| 36 |
end_of_week = start_of_week + timedelta(days=6)
|
| 37 |
|
| 38 |
filtered_tasks = []
|
| 39 |
-
for task in user_tasks.values():
|
| 40 |
task_date = datetime.strptime(task['date'], '%Y-%m-%d').date()
|
| 41 |
if section == "myDay" and task_date == today:
|
| 42 |
filtered_tasks.append(task)
|
|
@@ -48,7 +44,7 @@ def filter_tasks(section):
|
|
| 48 |
|
| 49 |
def check_deadlines():
|
| 50 |
today = datetime.now().date()
|
| 51 |
-
return [task for task in user_tasks.values() if today <= datetime.strptime(task['date'], '%Y-%m-%d').date() <= today + timedelta(days=2)]
|
| 52 |
|
| 53 |
def alert_user(upcoming_tasks):
|
| 54 |
procrastination_messages = []
|
|
@@ -69,52 +65,86 @@ def alert_user(upcoming_tasks):
|
|
| 69 |
procrastination_messages.append(procrastination_message)
|
| 70 |
return procrastination_messages
|
| 71 |
|
| 72 |
-
#
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
if "user_tasks" not in st.session_state:
|
| 77 |
st.session_state.user_tasks = {}
|
| 78 |
|
| 79 |
-
#
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
st.subheader("Upcoming Deadlines")
|
| 109 |
-
upcoming_tasks = check_deadlines()
|
| 110 |
-
if upcoming_tasks:
|
| 111 |
-
if st.button("Get Procrastination Message"):
|
| 112 |
-
messages = alert_user(upcoming_tasks)
|
| 113 |
-
st.info(random.choice(messages))
|
| 114 |
-
else:
|
| 115 |
-
st.info("No tasks with urgent deadlines.")
|
| 116 |
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
st.set_page_config(page_title="Task Manager with Procrastination Alerts", page_icon="π")
|
| 10 |
st.title("π Task Manager with Procrastination Alerts")
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
# Logging setup
|
| 13 |
logging.basicConfig(level=logging.INFO)
|
| 14 |
|
|
|
|
| 32 |
end_of_week = start_of_week + timedelta(days=6)
|
| 33 |
|
| 34 |
filtered_tasks = []
|
| 35 |
+
for task in st.session_state.user_tasks.values():
|
| 36 |
task_date = datetime.strptime(task['date'], '%Y-%m-%d').date()
|
| 37 |
if section == "myDay" and task_date == today:
|
| 38 |
filtered_tasks.append(task)
|
|
|
|
| 44 |
|
| 45 |
def check_deadlines():
|
| 46 |
today = datetime.now().date()
|
| 47 |
+
return [task for task in st.session_state.user_tasks.values() if today <= datetime.strptime(task['date'], '%Y-%m-%d').date() <= today + timedelta(days=2)]
|
| 48 |
|
| 49 |
def alert_user(upcoming_tasks):
|
| 50 |
procrastination_messages = []
|
|
|
|
| 65 |
procrastination_messages.append(procrastination_message)
|
| 66 |
return procrastination_messages
|
| 67 |
|
| 68 |
+
# Initialize session state variables
|
| 69 |
+
if "logged_in" not in st.session_state:
|
| 70 |
+
st.session_state.logged_in = False
|
|
|
|
| 71 |
if "user_tasks" not in st.session_state:
|
| 72 |
st.session_state.user_tasks = {}
|
| 73 |
|
| 74 |
+
# Login Page
|
| 75 |
+
def login():
|
| 76 |
+
st.subheader("Login")
|
| 77 |
+
with st.form("login_form"):
|
| 78 |
+
name = st.text_input("Name")
|
| 79 |
+
email = st.text_input("Email")
|
| 80 |
+
if st.form_submit_button("Login"):
|
| 81 |
+
if name and email:
|
| 82 |
+
st.session_state.logged_in = True
|
| 83 |
+
st.session_state.user_name = name
|
| 84 |
+
st.session_state.user_email = email
|
| 85 |
+
st.success("Logged in successfully.")
|
| 86 |
+
st.experimental_rerun()
|
| 87 |
+
else:
|
| 88 |
+
st.warning("Please enter both name and email.")
|
| 89 |
+
|
| 90 |
+
# Logout function
|
| 91 |
+
def logout():
|
| 92 |
+
st.session_state.logged_in = False
|
| 93 |
+
st.session_state.user_name = None
|
| 94 |
+
st.session_state.user_email = None
|
| 95 |
+
st.success("Logged out successfully.")
|
| 96 |
+
st.experimental_rerun()
|
| 97 |
+
|
| 98 |
+
# Main App
|
| 99 |
+
if st.session_state.logged_in:
|
| 100 |
+
st.sidebar.title(f"Welcome, {st.session_state.user_name}!")
|
| 101 |
+
if st.sidebar.button("Logout"):
|
| 102 |
+
logout()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
+
st.sidebar.title("Task Filters")
|
| 105 |
+
section = st.sidebar.radio("View Tasks", ["myDay", "thisWeek", "all"])
|
| 106 |
+
|
| 107 |
+
# Task Input Form
|
| 108 |
+
st.subheader("Add a New Task")
|
| 109 |
+
with st.form("add_task_form"):
|
| 110 |
+
task_text = st.text_input("Task Description")
|
| 111 |
+
due_date = st.date_input("Due Date")
|
| 112 |
+
if st.form_submit_button("Add Task"):
|
| 113 |
+
task_id = generate_numeric_id()
|
| 114 |
+
st.session_state.user_tasks[task_id] = {
|
| 115 |
+
"id": task_id,
|
| 116 |
+
"text": task_text,
|
| 117 |
+
"date": due_date.strftime('%Y-%m-%d'),
|
| 118 |
+
"completed": False
|
| 119 |
+
}
|
| 120 |
+
st.success("Task added successfully.")
|
| 121 |
+
|
| 122 |
+
# Display Tasks
|
| 123 |
+
st.subheader("Your Tasks")
|
| 124 |
+
tasks_to_display = filter_tasks(section)
|
| 125 |
+
for task in tasks_to_display:
|
| 126 |
+
col1, col2, col3 = st.columns([5, 1, 1])
|
| 127 |
+
col1.text(f"{task['text']} (Due: {task['date']})")
|
| 128 |
+
if col2.button("Toggle Complete", key=f"toggle_{task['id']}"):
|
| 129 |
+
task["completed"] = not task["completed"]
|
| 130 |
+
st.success(f"Task marked as {'completed' if task['completed'] else 'incomplete'}.")
|
| 131 |
+
if col3.button("Delete Task", key=f"delete_{task['id']}"):
|
| 132 |
+
del st.session_state.user_tasks[task["id"]]
|
| 133 |
+
st.success("Task deleted.")
|
| 134 |
+
|
| 135 |
+
# Procrastination Alerts
|
| 136 |
+
st.subheader("Upcoming Deadlines")
|
| 137 |
+
upcoming_tasks = check_deadlines()
|
| 138 |
+
if upcoming_tasks:
|
| 139 |
+
if st.button("Get Procrastination Message"):
|
| 140 |
+
messages = alert_user(upcoming_tasks)
|
| 141 |
+
st.info(random.choice(messages))
|
| 142 |
+
else:
|
| 143 |
+
st.info("No tasks with urgent deadlines.")
|
| 144 |
+
|
| 145 |
+
# Clear All Tasks
|
| 146 |
+
if st.button("Delete All Tasks"):
|
| 147 |
+
st.session_state.user_tasks.clear()
|
| 148 |
+
st.success("All tasks deleted.")
|
| 149 |
+
else:
|
| 150 |
+
login()
|