-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtodoapplication.py
182 lines (144 loc) · 5.62 KB
/
todoapplication.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
users = []
todos = []
logged_in_user = None
from os import system
system("cls")
def signup():
system("cls")
print("Signup Screen".center(50,"*"))
visitor = {'Uid': len(users)+1,'Name': input('Enter your name: '),'Username': input('Enter username: '),'Password': input('Enter password: ')}
# check if username is unique
all_users_username = [usr['Username'] for usr in users]
if visitor['Username'] in all_users_username:
print('Username is already taken, try different')
signup()
else:
print('User is registered!')
users.append(visitor)
#signup()
#signup()
#print(users)
def login():
system("cls")
global logged_in_user
print("Login Screen".center(50,"*"))
username = input('Enter username (case sensitive): ')
user_dict = None
for usr in users:
if usr['Username'] == username:
user_dict = usr
break
if not user_dict:
print('Username is incorrect')
login()
password= input('Enter password: ')
if user_dict:
if password == user_dict['Password']:
print('Login is successful')
logged_in_user = user_dict['Uid']
else:
print('password is incorrect')
login()
#signup()
#login()
#print(logged_in_user)
def addtodo():
system("cls")
print("Addtodo Screen".center(50,"*"))
if logged_in_user:
task = {'tid':len(todos)+1,
'Uid':logged_in_user,
'title':input("Enter title: "),
'status':input("Enter status: "),
'Deadline':input("Enter deadline: ")
}
todos.append(task)
ch = input('ADD MORE TASK? : ').lower()[0]
if ch == 'y':
addtodo()
else:
print('Please log in')
login()
addtodo()
'''signup()
login()
addtodo()
print(todos)'''
def showtodo():
system("cls")
print("Showtodo Screen".center(50,"*"))
if logged_in_user:
if todos:
for usr in todos:
if usr['Uid'] == logged_in_user:
print('TASK ID:',usr['tid'])
print('TASK TITLE:',usr['title'])
print('TASK STATUS:',usr['status'])
print('TASK DEADLINE:',usr['Deadline'])
print()
else:
print('Add some tasks')
addtodo()
else:
print('Please log in')
login()
showtodo()
def updatetodo():
system("cls")
global todos
print("Updatetodo Screen".center(50,"*"))
if logged_in_user:
task_id = int(input('Enter task id: '))
print()
update = {1:("Update Title",'title'),2:("Update Status","status"),3:("Update Deadline","Deadline")}
for num,option in update.items():
print(num,option[0],sep="---->")
print()
ch = int(input('ENTER OPTION: '))
if todos:
for usr in todos:
if usr['Uid'] == logged_in_user and usr['tid']==task_id:
if ch in update:
usr[update[ch][-1]] = input('New Value : ')
updates = input('Want to update something else? ').lower()[-1]
if updates == 'y':
updatetodo()
else:
print('ADD some tasks')
addtodo()
else:
print('Please log in')
login()
updatetodo()
def deletetodo():
system("cls")
global todos
print("deletetodo Screen".center(50,"*"))
if logged_in_user:
if todos:
task = int(input('Enter Task ID to delete: '))
for i in range(len(todos)):
if todos[i]['tid'] == task:
del todos[i]
break
else:
print('ADD SOME TASKS!')
addtodo()
else:
print('Please log in')
login()
deletetodo()
def exit():
global logged_in_user
logged_in_user = None
print("Logged out")
options = {1:("SIGN-UP",signup),2:("LOGIN",login),3:("ADD TODO",addtodo),4:("SHOW TODO",showtodo),5:("UPDATE TODO",updatetodo),6:("DELETE TODO",deletetodo),7:("EXIT",exit)}
while True:
print("Menu Screen".center(50,"*"))
for num,option in options.items():
print(num,option[0],sep="---->")
ch = int(input('ENTER OPTION: '))
if ch in options:
options[ch][-1]()
else:
print('INCORRECT OPTION')