Bhargavitippareddy commited on
Commit
051cfb4
·
verified ·
1 Parent(s): f9f1ffd

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +77 -0
app.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 = []
7
+
8
+ # Function to add task for each hour from 6 AM to 6 PM
9
+ def add_task_for_hour(hour):
10
+ # Format hour (6:00 AM, 7:00 AM, ..., 6:00 PM)
11
+ time_str = f"{hour}:00"
12
+
13
+ # Streamlit user input for each task
14
+ task = st.text_input(f"Enter the task for {time_str}:")
15
+
16
+ # Use the hour value as part of the key for unique text_area
17
+ description = st.text_area(f"Enter the description for {task}:", height=100, key=f"description_{hour}")
18
+
19
+ if task and description:
20
+ # Add the task to the list
21
+ daily_routine.append({"time": time_str, "task": task, "description": description})
22
+ st.success(f"Task for {time_str} added successfully!")
23
+
24
+ # Function to display the to-do list
25
+ def display_todo_list():
26
+ if len(daily_routine) == 0:
27
+ st.write("No tasks added yet.")
28
+ return
29
+
30
+ st.subheader("==== Daily Routine To-Do List (6 AM to 6 PM) ====")
31
+ for task in daily_routine:
32
+ st.write(f"**Time**: {task['time']}")
33
+ st.write(f"**Task**: {task['task']}")
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():
55
+ st.title("Daily Routine To-Do List (6 AM - 6 PM)")
56
+
57
+ # Loop through the hours from 6 AM to 6 PM
58
+ for hour in range(6, 19): # Loop from 6 AM (6) to 6 PM (18)
59
+ add_task_for_hour(hour)
60
+
61
+ # Display the to-do list
62
+ if len(daily_routine) > 0:
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()