-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask_manager_.py
More file actions
347 lines (223 loc) · 12.4 KB
/
task_manager_.py
File metadata and controls
347 lines (223 loc) · 12.4 KB
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
import math
from datetime import date
#------------------------------------------------LOGIN------------------------------------------------#
print("\n------------------------------------------------------------------------------\n")
#Open users.txt file as a read-only file, where the handle is positioned at the beginning of the file. This is also the default mode in which a file is opened.
user_list = open("users.txt", "r+")
#Use the readlines() function to read through each line in the file
#This returns each line as a list item
find_user = user_list.readlines()
#Set empty lists for users and passwords so that we can index each element
#This allows for the computer to search through each user and password
#Set an empty variable that stores which user has logged in
users = []
passwords = []
user_name = ""
#Use a for for loop to run through each element of the file
#For each line in the users.txt file use the split()function to split strings into a list
#Set the position for users in the list as[0]
#Set the positin for the passwords in the list as [1]
#Use the append() function to add each username and password to the users and passwords list
for line in find_user:
line = line.split(", ")
username = line[0]
password = line[1].replace("\n", "")
users.append(username)
passwords.append(password)
#Use a loop to run through the input of each user
#Set a variable for the input username and user password
#Use an if statement to determine if the username is in the users.txt file
#If the input username is in the users.txt file, then we set the index for the password to be the same as the username
while True:
user_name = input("\nPlease enter your username:\n\n")
if user_name in users:
password_index = users.index(user_name)
#If username and password match to one of the lines in the users.txt file, allow them in and break the loop
user_password = input("\n\nPlease enter your password:\n\n")
if user_password == passwords[password_index]:
print("\n\nWelcome to Task Manager, " + user_name)
break
#If the password is entered incorrectly, request password again and let them in if it's correct
else:
print("\nYou have entered an incorrect password.")
user_password = input("\n\nPlease enter your password again:\n\n")
if user_password == passwords[password_index]:
print("\n\nWelcome to Task Manager, " + user_name)
break
#If the username is incorrect, request username again
else:
print("\nYou have entered an incorrect username.")
#Close the users.txt file using the close() function
user_list.close()
#------------------------------------------------MENU-------------------------------------------------------------#
#Use a loop to present the menu to the user
#Use the lower()function to convert inputs to lowercase
print("\n------------------------------------------------------------------------------\n")
while True:
menu = input('''\n\nSelect one of the following Options below:\n
r - Registering a user
a - Adding a task
va - View all tasks
vm - View my task
s - View statistics
e - Exit
\n\n''').lower()
#------------------------------------------------REGISTER USER---------------------------------------------------#
#Use an if statement if the user selects 'r'
#Set a condition that the username has to be admin in order to register a new user
if menu == 'r' and user_name == "admin":
#Open the users.txt file in 'a' mode, where the handle is positioned at the end of the file. The data being written will be inserted at the end, after the existing data.
user_list = open("users.txt", "a")
#Use a loop to get the information for the new user
while True:
new_user_name = input("\n\nPlease enter the new username that you wish to add:\n\n").lower()
new_user_password = input("\n\nPlease enter their password:\n\n")
confirm_password = input("\n\nPlease confirm password:\n\n")
#If the passwords do not match, request confirmation again
if new_user_password != confirm_password:
print("\n\nThe passwords do not match. Please try again.\n\n")
#If the passwords match, add the new user information to the users.txt file
#Use the format{} function to write the user information with the same format as previous users
elif new_user_password == confirm_password:
print("\n\nThank you!\n\n")
print(new_user_name + " has been added to your database.\n\n")
new_user = f"{new_user_name}, {new_user_password}\n"
user_list.write(new_user)
#If username isn't admin, prompt to choose another option from the menu
else:
print("\nSorry, you do not have access to register new users!\n")
print("\nPlease choose another option from the menu below.\n")
#Close the file and break the loop
user_list.close()
#------------------------------------------------ADD TASK-------------------------------------------------------#
#If user selects 'a' to add a task
#Open the tasks.txt file in 'a' mode where the handle is positioned at the end of the file. The data being written will be inserted at the end, after the existing data.
elif menu == 'a':
#Set new input variables for each task element
#Use the date() function to pull today's date
#For the due date set it in the same format as the current date
new_task = open("tasks.txt", "a")
assign_task = input("\n\nPlease assign a username to the task:\n\n")
title_task = input("\n\nPlease confirm the title of the task:\n\n")
description = input("\n\nPlease write a description of the task:\n\n")
current_date = date.today()
due_date = input("\n\nPlease enter the due date for this task (format YYYY-MM-DD):\n\n")
task_completion = input("\n\nPlease confirm if the task is completed or not (Yes or No):\n\n")
#Write the new task onto the tasks.txt file using the format{} function
new_task.write(f"{assign_task}, {title_task}, {description}, {current_date}, {due_date}, {task_completion}\n")
print("\n\nThank you, your task has been added to 'tasks.txt'\n\n")
# print("\nPlease choose another option from the menu below.\n")--------ask sash how to go back to menu
#Close the file and break the loop
new_task.close()
break
#------------------------------------------------VIEW TASKS-----------------------------------------------------#
#If the user selects the 'va' option to view all tasks
#Open the tasks.txt file as read only, where the handle is positioned at the beginning of the file. This is also the default mode in which a file is opened.
elif menu == 'va':
#Set empty list variables for each task element so that we can index them
#Use the readlines() function to read through each line in the file
view_tasks = open("tasks.txt", "r")
find_task = view_tasks.readlines()
assign_task = []
title_task = []
description = []
current_date = []
due_date = []
task_completion = []
#Use a for loop to run through each element of the file
#For each line in the tasks.txt file use the split()function to split strings into a list
#Set the positions for each task element
for lines in find_task:
lines = lines.split(", ")
assign_task = lines[0]
title_task = lines[1]
description = lines[2]
current_date = lines[3]
due_date = lines[4]
task_completion = lines[5]
#Print out the tasks in the requested format, using indexing
#Convert each element to a string so that the print function works
print("\n------------------------------------------------------------------------------\n")
print("Task:\t\t\t\t" + str(title_task))
print("Assigned to:\t\t\t" + str(assign_task))
print("Date assigned:\t\t\t" + str(current_date))
print("Due Date:\t\t\t" + str(due_date))
print("Task complete?\t\t\t" + str(task_completion))
print("Task Description:\n" + str(description))
print("\n------------------------------------------------------------------------------\n")
#Close file and break menu loop
view_tasks.close()
#------------------------------------------------VIEW MY TASK(S)----------------------------------------------#
#If the user selects 'vm' to view my task(s)
#Open both users.txt and tasks.txt file as read only, where the handle is positioned at the beginning of the file. This is also the default mode in which a file is opened.
#Use readlines() function to read through each line in the files
elif menu == 'vm':
username_find = open("users.txt", "r")
find_users = username_find.readlines()
view_user_task = open("tasks.txt", "r")
#Set empty list variables for users and tasks for indexing purposes
users = []
tasks = []
#Get username from user
input_username = input("\n\nPlease enter your username:\n\n")
#If username is incorrect, prompt accordingly
#For each line in the users.txt file use the split()function to split strings into a list
#Set users element as position [0]
for line in find_users:
line = line.split(", ")
username = line[0]
#If username is incorrect, prompt accordingly
if input_username != users:
print("\nYou have entered an incorrect username.\n")
input_username = input("\nPlease enter your username again:\n")
#For each line in the tasks.txt file use the split()function to split strings into a list
#Set tasks element as position [0], matching with the user position
for line in view_user_task:
split_data = line.split(", ")
if input_username == split_data[0]:
#Print in the requested format, using indexing
#Convert each element to a string so that the print function works
print("\n------------------------------------------------------------------------------\n")
print("Task:\t\t\t\t" + split_data[1])
print("Assigned to:\t\t\t" + split_data[0])
print("Date assigned:\t\t\t" + split_data[3])
print("Due Date:\t\t\t" + split_data[4])
print("Task complete?\t\t\t" + split_data[5])
print("Task Description:\n" + split_data[2] + "\n")
print("\n------------------------------------------------------------------------------\n")
#Close file and break menu loop
view_user_task.close()
#------------------------------------------------STATISTICS-------------------------------------------------#
#Open both users.txt and tasks.txt file as read only, where the handle is positioned at the beginning of the file. This is also the default mode in which a file is opened.
elif menu == 's' and user_name == "admin":
print("\nWelcome, Admin!\n")
usernames = open("users.txt", "r")
tasks = open("tasks.txt", "r")
#Set counter to 0 for each file
tasks_num = 0
users_num = 0
#For each line in the tasks file, count in increments of 1
#Print using the format function
for line in tasks:
tasks_num += 1
print("\n------------------------------------------------------------------------------\n")
print (f"\nTotal number of tasks:\t\t\t {tasks_num}")
#For each line in the usernames file, count in increments of 1
#Print using the format function
for line in usernames:
users_num += 1
print (f"\nTotal number of users:\t\t\t {users_num}\n")
print("\n------------------------------------------------------------------------------\n")
#Close each file and break the menu loop
usernames.close()
tasks.close()
break
#------------------------------------------------EXIT------------------------------------------------------#
#If user selects 'e' to exit
#Say goodbye
elif menu == 'e':
print('Goodbye!!!')
exit()
#If user selects invalid menu choice, restart loop
else:
print("\nYou have made a wrong choice, please try again.")