Question: Compulsory Task 1 Follow these steps: Create a copy of your previous Capstone project (task_manager.py) and save it in the Dropbox folder for this project.
Compulsory Task 1
Follow these steps:
Create a copy of your previous 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. In this task you will be modifying this program.
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 dont 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 havent 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 task_manager.py.
For each user also describe:
The total number of tasks assigned to that user.
The percentage of the total number of tasks that have
been assigned to that user
The percentage of the tasks assigned to that user that
have been completed
The percentage of the tasks assigned to that user that
must still be completed
The percentage of the tasks assigned to that user that
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. If these text files dont exist (because the user hasnt selected to generate them yet), first call the code to generate the text files.
MY PREVIOUS CODE:
from datetime import datetime
file = open("user.txt","r")
lines = file.readlines()
for line in lines:
p_w = line.strip()
p_w = p_w.split()
p_w = p_w[1]
for line in lines:
u_n = line.strip()
u_n = u_n.split(",")
u_n = u_n[0]
username = input("Enter username: ")
while username != u_n:
print("Invalid Username!")
username = input("Enter username: ")
if username == u_n:
password = input("Enter password: ")
while password != p_w:
print("Invalid Password!")
password = input("Enter password: ")
file.close()
while True:
if username == "admin":
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
d - stats
e - Exit
: ''').lower()
else:
menu = input('''Select one of the following Options below:
a - Adding a task
va - View all tasks
vm - view my task
e - Exit
: ''').lower()
if menu == 'r' and username == 'admin':
new_user = (input("Please enter a new user name: "))
new_user_password = (input("Please enter a new password: "))
new_password = False
while new_password == False:
confirm_new_password = input("Please retype your password to confirm: ")
if new_user_password == confirm_new_password:
new_password = True
elif new_password == False:
print("Your passwords do not match!")
with open ('user.txt', 'a')as user_file:
user_file.write(f" {new_user}, {new_user_password}")
elif menu == "d" and username == 'admin':
tasks_num = 0
users_num = 0
with open("tasks.txt", "r") as task_file:
for line in task_file:
tasks_num += 1
print (f" Total number of tasks: {tasks_num}")
with open("user.txt", "r") as username:
for line in username:
users_num += 1
print (f"Total number of users: {users_num}")
elif menu == 'a':
employee = input("Enter username of person whom task is assigned to: ")
task_title = input("Enter the title of the task: ")
task_description = input("Enter description of task: ")
date_entry = input("Enter due date of task in the following way: ex:(1 Feb 2023)")
task_due_date = datetime.strptime(date_entry, '%d %b %Y')
task_due_date = datetime.strftime(task_due_date,'%d %b %Y')
task_complete = "No"
task_assigned = datetime.now()
task_assigned =datetime.strftime(task_assigned,'%d %b %Y')
all_task = f'{employee}, {task_title}, {task_description}, {task_assigned}, {task_due_date}, {task_complete}'
task_file = open ("tasks.txt","a")
task_file.write(' '+all_task)
task_file.close()
elif menu == 'va':
task_file = open("tasks.txt","r")
task_lines = task_file.readlines()
task_file.close()
for section in task_lines:
part = section.strip()
part = part.split(", ")
print(f"Task: "," ",part[1])
print(f"Assigned to: "," ",part[0])
print(f"Date assigned"," ",part[3])
print(f"Due date: "," ",part[4])
print(f"Task Complete? "," ",part[-1])
print(f"Task Description: "," ",part[2:3])
elif menu == 'vm':
specific_task_file = open("tasks.txt","r")
specific_task_lines = specific_task_file.readlines()
specific_task_file.close()
for specific_section in specific_task_lines:
specific_part = specific_section.strip()
specific_part = specific_part.split(", ")
if username == specific_part[0]:
print(f"Task: "," ",specific_part[1])
print(f"Assigned to: "," ",specific_part[0])
print(f"Date assigned"," ",specific_part[3])
print(f"Due date: "," ",specific_part[4])
print(f"Task Complete? "," ",specific_part[-1])
print(f"Task Description: "," ",specific_part[2:3])
elif menu == 'e':
print('Goodbye!!!')
exit()
else:
print("You have made a wrong choice, Please Try again")
Step by Step Solution
There are 3 Steps involved in it
Updated taskmanagerpy as per Compulsory Task 1 Here is the fully modular version of your program with all requested functionality python from datetime import datetime dateimport os Helper Functions de... View full answer
Get step-by-step solutions from verified subject matter experts
