make a copy of Capstone project (task_manager.py) and save it in the Dropbox folder for this project.
Question:
make a copy of Capstone project (task_manager.py) and save it in the Dropbox folder for this project. Also, copy and paste the text files (user.txt and tasks.txt) that accompanied the previous Capstone project to this folder. Modify this program as follows:
● Modify the code of your previous project so that functions are used. Adding functions will improve the modularity of your code. Your program should include at least the following functions: o reg_user — that is called when the user selects 'r' to register a user. o add_task — that is called when a user selects 'a' to add a new task. o view_all — that is called when users type 'va' to view all the tasks listed in 'tasks.txt'. o view_mine — that is called when users type 'vm' to view all the tasks that have been assigned to them.
● Modify the function called reg_user to make sure that you don't duplicate usernames when you add a new user to user.txt. If a user tries to add a username that already exists in user.txt, provide a relevant error message and allow them to try to add a user with a different username.
● Add the following functionality when the user selects 'vm' to view all the tasks assigned to them: o Display all tasks in a manner that is easy to read. Make sure that each task is displayed with a corresponding number which can be used to identify the task. o Allow the user to select either a specific task by entering a number or input '-1' to return to the main menu. o If the user selects a specific task, they should be able to choose to either mark the task as complete or edit the task. If the user chooses to mark a task as complete, the 'Yes'/'No' value that describes whether the task has been completed or not should be changed to 'Yes'. When the user chooses to edit a task, the username of the person to whom the task is assigned or the due date of the task can be edited. The task can only be edited if it has not yet been completed Add an option to generate reports to the main menu of the application. The menu for the admin user should now look something like this:
● When the user chooses to generate reports, two text files, called task_overview.txt and user_overview.txt, should be generated. Both these text files should output data in a user-friendly, easy to read manner. o task_overview.txt should contain: ▪ The total number of tasks that have been generated and tracked using the task_manager.py. ▪ The total number of completed tasks. ▪ The total number of uncompleted tasks.
▪ The total number of tasks that haven't been completed and that are overdue. ▪ The percentage of tasks that are incomplete. ▪ The percentage of tasks that are overdue. o user_overview.txt should contain: ▪ The total number of users registered with task_manager.py. ▪ The total number of tasks that have been generated and tracked using the task_manager.py. ▪ For each user also describe: ▪ The total number of tasks assigned to that user. ▪ What percentage of the total number of tasks have been assigned to that user? ▪ What percentage of the tasks assigned to that user have been completed? ▪ What percentage of the tasks assigned to that user must still be completed? ▪ What percentage of the tasks assigned to that user have not yet been completed and are overdue?
● Modify the menu option that allows the admin to display statistics so that the reports generated are read from task_overview.txt and user_overview.txt and displayed on the screen in a user-friendly manner.
here is my code for the previous project that you need to add the code on:
import datetime
users = []
passwords = []
user_name = ""
total_users = []
total_tasks = []
details = False
# open both user and task files
with open("user.txt", 'r+') as f:
for line in f:
total_users.append(line.split())
#validating the user username and password by allowing the
#user to enter their username and password
while True:
username = input("Enter your username: ")
password = input("Enter your password: ")
for i in range(len(total_users)):
if username and password in total_users[i]:
details = True
if details == True:
break
else:
print("Enter a valid username/ password.")
while True:
#presenting the menu to the user and
# making sure that the user input is coneverted to lower case.
menu = input('''Select one of the following Options below:
r - Registering a user
a - Adding a task
va - View all tasks
vm - view my task
e - Exit
: ''').lower()
if menu == 'r':
#if user chooses r then they may be asked to enter new username,
#new password, confirm password
if username == "admin":
new_username = input("Enter the new user's username: ")
new_password = input("Enter the new user's password: ")
new_password_confirm = input("Confirm the new user's password: ")
#if the password matches, the te new password is stored to the file
if new_password == new_password_confirm:
user_file = open("user.txt", "a")
user_file.write("\n" + new_username + ", " + new_password)
user_file.close()
print("The new user has been registered.")
else:print("The new password and confirmed password do not match, please try again.")
#if menu a is chosen user iformation about the task is required
elif menu == 'a':
#user inputs title, description, due date, username of the person,
#due date of the task and is stored in the variables below
username_assigned = input("Enter the username of the person the task is assigned to: ")
task_title = input("Enter the title of the task: ")
task_description = input("Enter the description of the task: ")
task_due_date = input("Enter the due date of the task (dd/mm/yyyy): ")
#open file task.txt to write the data above
task_file = open("tasks.txt", "a")
task_file.write("\n" + username_assigned + ", " + task_title + ", " + task_description + ", " + str(datetime.date.today()) + ", " + task_due_date + ", No")
task_file.close()
print("The task has been added.")
elif menu == 'va':
file = open("tasks.txt", "r")
for line in file:
# if the line is not empty
if line != "\n":
# split the line into a list
line = line.split(",")
# remove the \n character
line[-1] = line[-1].strip()
# print the details of each task
print("Task:\t\t\t\t" + line[1])
print("Assigned to:\t\t\t" + line[0])
print("Date assigned:\t\t\t" + line[3])
print("Due Date:\t\t\t" + line[4])
print("Task complete?\t\t\t" + line[5])
print("Task Description:\n" + line[2])
print("\n------------------------------------------------------------------------------\n")
elif menu == 'vm':
file = open("tasks.txt", "r")
# go through each line in the tasks.txt file
for line in file:
#if the line is not empty
if line != "\n":
# split the line into a list
line = line.split(",")
# split the line into a list
line = line.split(",")
# remove the \n character
line[-1] = line[-1].strip()
# if the username on the current line is the same as the username that is logged in
if line[0] == username:
# print the details of each task
print("\n------------------------------------------------------------------------------\n")
print("Task:\t\t\t\t" + line[1])
print("Assigned to:\t\t\t " + " " + line[0])
print("Date assigned:\t\t\t" + line[3])
print("Due Date:\t\t\t" + line[4])
print("Task complete?\t\t\t " +" "+ line[5])
print("Task Description:\n" + line[2] + "\n")
print("\n------------------------------------------------------------------------------\n")
file.close()
elif menu == "s":
#if username is admin, allow the program to be executed if not a message is displayed
if username != "admin":
print("Only admins can access statistics.")
elif username == "admin":
user_count = "user.txt"
counting = 0
with open('user.txt', 'r') as f:
for line in f:
counting += 1
print("Total users are: ", counting)
# create function to count the number of tasks in the file
task_count = "tasks.txt"
task_counting = 0
with open('tasks.txt', 'r') as g:
for line in g:
task_counting += 1
print("Total tasks are: ", task_counting)
#print exit when the user enter e
elif menu == 'e':
print("Goodbye!!!")
exit()
else:
print("You have made a wrong choice, Please Try again")
user textfile:
admin, adm1n
aya, 23
asiphe, 2
Qamata, 24
Qama, 20
someleze, 21
Max, 24
task textfile:
admin, Register Users with taskManager.py, Use taskManager.py to add the usernames and passwords for all team members that will be using this program., 10 Oct 2019, 20 Oct 2019, No
admin, Assign initial tasks, Use taskManager.py to assign each team member with appropriate tasks, 10 Oct 2019, 25 Oct 2019, No
Qama, Arts, Drama, 2022-12-12, 12/12, No
va, vm, e, 2022-12-12, e, No
someleze, driving, inlcine, 2022-12-12, 12/23/2022, No
Max, Operations, Handheld readings, 2022-12-12, 12/12/2022, No
hh, hhh, j, 2022-12-12, jj, No
Microsoft Visual C# An Introduction to Object-Oriented Programming
ISBN: 978-1337102100
7th edition
Authors: Joyce Farrell