Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import csv | |
| import io | |
| # Initialize an empty list for storing the daily routine | |
| daily_routine = [] | |
| # Function to add task for each hour from 6 AM to 6 PM | |
| def add_task_for_hour(hour): | |
| # Format hour (6:00 AM, 7:00 AM, ..., 6:00 PM) | |
| time_str = f"{hour}:00" | |
| # Streamlit user input for each task | |
| task = st.text_input(f"Enter the task for {time_str}:") | |
| # Use the hour value as part of the key for unique text_area | |
| description = st.text_area(f"Enter the description for {task}:", height=100, key=f"description_{hour}") | |
| if task and description: | |
| # Add the task to the list | |
| daily_routine.append({"time": time_str, "task": task, "description": description}) | |
| st.success(f"Task for {time_str} added successfully!") | |
| # Function to display the to-do list | |
| def display_todo_list(): | |
| if len(daily_routine) == 0: | |
| st.write("No tasks added yet.") | |
| return | |
| st.subheader("==== Daily Routine To-Do List (6 AM to 6 PM) ====") | |
| for task in daily_routine: | |
| st.write(f"**Time**: {task['time']}") | |
| st.write(f"**Task**: {task['task']}") | |
| st.write(f"**Description**: {task['description']}") | |
| st.markdown("---") | |
| # Function to save the daily routine to a CSV file in memory (using StringIO) | |
| def save_to_csv(): | |
| # Create a StringIO object to hold the CSV data in memory | |
| csv_buffer = io.StringIO() | |
| # Write to the buffer | |
| writer = csv.writer(csv_buffer) | |
| writer.writerow(["Time", "Task", "Description"]) # Write headers | |
| for task in daily_routine: | |
| writer.writerow([task['time'], task['task'], task['description']]) | |
| # Move the buffer's cursor to the beginning of the file | |
| csv_buffer.seek(0) | |
| return csv_buffer.getvalue() | |
| # Streamlit UI | |
| def main(): | |
| st.title("Daily Routine To-Do List (6 AM - 6 PM)") | |
| # Loop through the hours from 6 AM to 6 PM | |
| for hour in range(6, 19): # Loop from 6 AM (6) to 6 PM (18) | |
| add_task_for_hour(hour) | |
| # Display the to-do list | |
| if len(daily_routine) > 0: | |
| if st.button("Display To-Do List"): | |
| display_todo_list() | |
| # Save the list to CSV and provide a download button | |
| if len(daily_routine) > 0: | |
| csv_data = save_to_csv() | |
| st.download_button( | |
| label="Download Daily Routine as CSV", | |
| data=csv_data, | |
| file_name="daily_routine.csv", | |
| mime="text/csv" | |
| ) | |
| if __name__ == "__main__": | |
| main() | |