Miaaaaaaaa commited on
Commit
66feb8f
1 Parent(s): bbb0410

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +80 -0
  2. requirements.txt +0 -0
app.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pymongo
3
+
4
+ url='mongodb+srv://baoyuxin1994:0817@cluster0.rcvcj3s.mongodb.net/?retryWrites=true&w=majority'
5
+ client=pymongo.MongoClient(url)
6
+ db=client['todo']
7
+ collection=db['tasks']
8
+
9
+ st.title('TODO app')
10
+
11
+
12
+ page=st.sidebar.selectbox('Menu',['Home','Insert','Edit','Delete'])
13
+
14
+ if page=='Insert':
15
+ st.header('Insert Task')
16
+ task=st.text_input('Task')
17
+ category=st.selectbox('Category',['','Work','Personal','Shopping'])
18
+ ranking=st.slider('Priority', 0, 5, 0)
19
+
20
+ if st.button('Insert your task'):
21
+ if task.strip() == "":
22
+ st.warning('Task can not be empty',icon='⚠️')
23
+ elif category.strip() == "":
24
+ st.warning('Category can not be empty',icon='⚠️')
25
+ elif ranking == 0:
26
+ st.warning('Priority can not be 0',icon='⚠️')
27
+ else:
28
+ collection.insert_one({'task':task, 'category':category,'Priority':ranking})
29
+ st.success('Successfully Inserted')
30
+
31
+ elif page=='Edit':
32
+ st.header('Edit Task')
33
+
34
+ _task = collection.find({},{'task':1,'_id':0})
35
+ _task_list=[]
36
+ for t in _task:
37
+ _task_list.append(t['task'])
38
+
39
+ old_one=st.selectbox('Select the one to edit',_task_list)
40
+
41
+ new_one=st.text_input('New Task')
42
+ category=st.selectbox('Category',['','Work','Personal','Shopping'])
43
+ ranking=st.slider('Priority', 0, 5, 0)
44
+
45
+ if st.button('Edit your task'):
46
+ if new_one.strip() == "":
47
+ st.warning('Task can not be empty',icon='⚠️')
48
+ elif category.strip() == "":
49
+ st.warning('Category can not be empty',icon='⚠️')
50
+ elif ranking == 0:
51
+ st.warning('Priority can not be 0',icon='⚠️')
52
+ else:
53
+ collection.replace_one(collection.find_one({},{'task':old_one}),{'task':new_one,'category':category,'Priority':ranking})
54
+ st.success('Successfully Edited')
55
+
56
+ elif page=='Delete':
57
+ st.header('Delete Task')
58
+ tasks=collection.find({},{'_id':0})
59
+
60
+ _task = collection.find({},{'task':1,'_id':0})
61
+ _task_list=[]
62
+
63
+ for t in _task:
64
+ _task_list.append(t['task'])
65
+
66
+ delete_the_task=st.selectbox('Delete',_task_list)
67
+
68
+ if st.button('Delete your task'):
69
+ collection.delete_one({'task':delete_the_task})
70
+ st.success('Successfully Deleted')
71
+
72
+
73
+ elif page=='Home':
74
+ st.header('Home')
75
+ st.write('This is a Todo list which allows you to read, insert,edit and delete')
76
+ #tasks=collection.find({},{'_id':0})
77
+ #st.table(tasks)
78
+
79
+ all_tasks=collection.find({},{'_id':0}).sort({'Priority':-1,})
80
+ st.table(all_tasks)
requirements.txt ADDED
Binary file (1.71 kB). View file