Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import csv
|
|
|
|
| 3 |
|
| 4 |
# Initialize an empty list for storing the daily routine
|
| 5 |
daily_routine = []
|
|
@@ -33,18 +34,21 @@ def display_todo_list():
|
|
| 33 |
st.write(f"**Description**: {task['description']}")
|
| 34 |
st.markdown("---")
|
| 35 |
|
| 36 |
-
# Function to save the daily routine to a CSV file
|
| 37 |
-
def save_to_csv(
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
# Streamlit UI
|
| 50 |
def main():
|
|
@@ -59,9 +63,15 @@ def main():
|
|
| 59 |
if st.button("Display To-Do List"):
|
| 60 |
display_todo_list()
|
| 61 |
|
| 62 |
-
# Save the list to a
|
| 63 |
-
if
|
| 64 |
-
save_to_csv(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
if __name__ == "__main__":
|
| 67 |
main()
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import csv
|
| 3 |
+
import io
|
| 4 |
|
| 5 |
# Initialize an empty list for storing the daily routine
|
| 6 |
daily_routine = []
|
|
|
|
| 34 |
st.write(f"**Description**: {task['description']}")
|
| 35 |
st.markdown("---")
|
| 36 |
|
| 37 |
+
# Function to save the daily routine to a CSV file in memory (using StringIO)
|
| 38 |
+
def save_to_csv():
|
| 39 |
+
# Create a StringIO object to hold the CSV data in memory
|
| 40 |
+
csv_buffer = io.StringIO()
|
| 41 |
+
|
| 42 |
+
# Write to the buffer
|
| 43 |
+
writer = csv.writer(csv_buffer)
|
| 44 |
+
writer.writerow(["Time", "Task", "Description"]) # Write headers
|
| 45 |
+
for task in daily_routine:
|
| 46 |
+
writer.writerow([task['time'], task['task'], task['description']])
|
| 47 |
+
|
| 48 |
+
# Move the buffer's cursor to the beginning of the file
|
| 49 |
+
csv_buffer.seek(0)
|
| 50 |
+
|
| 51 |
+
return csv_buffer.getvalue()
|
| 52 |
|
| 53 |
# Streamlit UI
|
| 54 |
def main():
|
|
|
|
| 63 |
if st.button("Display To-Do List"):
|
| 64 |
display_todo_list()
|
| 65 |
|
| 66 |
+
# Save the list to CSV and provide a download button
|
| 67 |
+
if len(daily_routine) > 0:
|
| 68 |
+
csv_data = save_to_csv()
|
| 69 |
+
st.download_button(
|
| 70 |
+
label="Download Daily Routine as CSV",
|
| 71 |
+
data=csv_data,
|
| 72 |
+
file_name="daily_routine.csv",
|
| 73 |
+
mime="text/csv"
|
| 74 |
+
)
|
| 75 |
|
| 76 |
if __name__ == "__main__":
|
| 77 |
main()
|