📜  Python中的个性化任务管理器

📅  最后修改于: 2022-05-13 01:57:41.710000             🧑  作者: Mango

Python中的个性化任务管理器

在本文中,我们将使用Python创建一个任务管理软件。对于那些不想为自己完成的任务和剩下的任务而负担的人来说,该软件将非常有用。作为一名程序员,我们必须记住正在进行的比赛、我们注册的课程以及我们关注的 YouTube 播放列表等等。该软件将以安全的方式记录所有此类详细信息,以便只有您可以访问您的数据。

项目中使用的工具和技术:

  • 这个项目将非常适合初学者。
  • 该软件的工作完全是POP(面向过程的编程)。需要有关Python函数的基本知识。
  • Python的日期时间模块。

构建项目所需的技能:

  • Python
  • Visual Studio Code 或任何其他代码编辑器。

分步实施:

按照以下步骤使用Python实现个性化的任务管理器:

  • 第 1 步:创建一个文件夹名称“任务管理器”。在您喜欢的代码编辑器中打开它。
  • 第 2 步:创建一个名为“task_manager.py”的Python文件。
  • 第 3 步:现在我们已准备好对我们的软件进行编码。最初,我们将从创建我们的注册函数开始。注册函数将使用用户将要创建他/她的帐户的用户名,并要求为该帐户设置密码。下面的代码将使事情变得清晰。
Python3
def signup():
    print("Please enter the username by which you \
    wanna access your account")
    username = input("please enter here:  ")
    password = input("Enter a password:  ")


Python3
# pssd means password, ussnm is username
def user_information(ussnm, pssd):
    name = input("enter your name please: ")
    address = input("your address")
    age = input("Your age please")
    ussnm_ = ussnm+" task.txt"
     
    f = open(ussnm_, 'a')
    f.write(pssd)
    f.write("\nName: ")
    f.write(name)
    f.write('\n')
    f.write("Address :")
 
    f.write(address)
    f.write('\n')
    f.write("Age :")
    f.write(age)
    f.write('\n')
    f.close()
 
 
def signup():
    print("Please enter the username by which you\
    wanna access your account")
    username = input("please enter here:  ")
    password = input("Enter a password:  ")
    user_information(username, password)


Python3
def login():
    print("Please enter your username ")
    user_nm = input("Enter here: ")
     
    # Password as entered while logging in
    pssd_wr = (input("enterr the password"))+'\n'
    try:
        usernm = user_nm+" task.txt"
        f_ = open(usernm, 'r')
         
        # variable 'k' contains the password as saved
        # in the file
        k = f_.readlines(0)[0]
        f_.close()
         
         # Checking if the Password entered is same as
         # the password saved while signing in
        if pssd_wr == k:
            print(
                "1--to view your data \n2--To add task \n3--Update\
                task status \n4--View task status")
            a = input()
        else:
            print("SIR YOUR PASSWORD OR USERNAME IS WRONG , Plz enter Again")
            login()
    except Exception as e:
        print(e)
        login()


Python3
def signup():
    print("Please enter the username by which you wanna access your account")
    username = input("please enter here:  ")
    password = input("Enter a password:  ")
    user_information(username, password)
    print("Sir please proceed towards log in")
    login()


Python3
def login():
    print("Please enter your username ")
    user_nm = input("Enter here: ")
     
    # Password as entered while logging in
    pssd_wr = (input("enterr the password"))+'\n'
    try:
        usernm = user_nm+" task.txt"
        f_ = open(usernm, 'r')
         
        # variable 'k' contains the password as
        # saved in the file
        k = f_.readlines(0)[0]
        f_.close()
         
         # Checking if the Password entered is same
         # as the password saved while signing in
        if pssd_wr == k:
            print(
                "1--to view your data \n2--To add task \n3--Update\
                task \n4--VIEW TASK STATUS")
            a = input()
             
            if a == '1':
                view_data(usernm)
            elif a == '2':
                # add task
                task_information(usernm)
            elif a == '3':
                task_update(user_nm)
            elif a == '4':
                task_update_viewer(user_nm)
            else:
                print("Wrong input ! ")
        else:
            print("SIR YOUR PASSWORD OR USERNAME IS WRONG")
            login()
 
    except Exception as e:
        print(e)
        login()
 
 
def view_data(username):
    pass
 
def task_information(username):
    pass
 
def task_update(username):
    pass
 
def task_update_viewer(username):
    pass


Python3
def view_data(username):
    ff = open(username, 'r')
    print(ff.read())
    ff.close()


Python3
def task_information(username):
    print("Sir enter n.o of task you want to ADD")
    j = int(input())
    f1 = open(username, 'a')
     
    for i in range(1, j+1):
        task = input("enter the task")
        target = input("enter the target")
        pp = "TASK "+str(i)+' :'
        qq = "TARGET "+str(i)+" :"
         
        f1.write(pp)
        f1.write(task)
        f1.write('\n')
        f1.write(qq)
        f1.write(target)
        f1.write('\n')
         
        print("Do u want to stop press space bar otherwise enter")
        s = input()
        if s == ' ':
            break
    f1.close()


Python3
def task_update(username):
    username = username+" TASK.txt"
    print("Please enter the tasks which are completed ")
     
    task_completed = input()
    print("Enter task which are still not started by you")
     
    task_not_started = input()
    print("Enter task which you are doing")
     
    task_ongoing = input()
    fw = open(username, 'a')
    DT = str(datetime.datetime.now())
     
    fw.write(DT)
    fw.write("\n")
    fw.write("COMPLETED TASK \n")
    fw.write(task_completed)
    fw.write("\n")
    fw.write("ONGOING TASK \n")
    fw.write(task_ongoing)
    fw.write("\n")
    fw.write("NOT YET STARTED\n")
    fw.write(task_not_started)
    fw.write("\n")


Python3
def task_update_viewer(username):
    ussnm = username+" TASK.txt"
    o = open(ussnm, 'r')
    print(o.read())
    o.close()


Python3
if __name__ == '__main__':
    print("WELCOME TO ANURAG`S TASK MANAGER")
    print("sir are you new to this software")
    a = int(input("Type 1 if new otherwise press 0 ::"))
     
    if a == 1:
        signup()
    elif a == 0:
        login()
    else:
        print("You have provided wrong input !")


Python3
import datetime
 
# pssd means password, ussnm is username
def user_information(ussnm, pssd): 
    name = input("enter your name please: ")
    address = input("your address")
    age = input("Your age please")
    ussnm_ = ussnm+" task.txt"
    f = open(ussnm_, 'a')
    f.write(pssd)
    f.write("\nName: ")
    f.write(name)
    f.write('\n')
    f.write("Address :")
 
    f.write(address)
    f.write('\n')
    f.write("Age :")
    f.write(age)
    f.write('\n')
    f.close()
 
 
def signup():
    print("Please enter the username by which you wanna access your account")
    username = input("please enter here:  ")
    password = input("Enter a password:  ")
    user_information(username, password)
    print("Sir please proceed towards log in")
    login()
 
 
def login():
    print("Please enter your username ")
    user_nm = input("Enter here: ")
     
    # Password as entered while logging in
    pssd_wr = (input("enterr the password"))+'\n'
    try:
        usernm = user_nm+" task.txt"
        f_ = open(usernm, 'r')
         
        # variable 'k' contains the password as saved
        # in the file
        k = f_.readlines(0)[0]
        f_.close()
         
        # Checking if the Password entered is same as
        # the password saved while signing in
        if pssd_wr == k:  
            print(
                "1--to view your data \n2--To add task \n3--Update\
                task \n4--VIEW TASK STATUS")
            a = input()
             
            if a == '1':
                view_data(usernm)
            elif a == '2':
                # add task
                task_information(usernm)
            elif a == '3':
                task_update(user_nm)
            elif a == '4':
                task_update_viewer(user_nm)
            else:
                print("Wrong input ! bhai dekh kr input dal")
        else:
            print("SIR YOUR PASSWORD OR USERNAME IS WRONG")
            login()
 
    except Exception as e:
        print(e)
        login()
 
 
def view_data(username):
    ff = open(username, 'r')
    print(ff.read())
    ff.close()
 
 
def task_information(username):
    print("Sir enter n.o of task you want to ADD")
    j = int(input())
    f1 = open(username, 'a')
     
    for i in range(1, j+1):
        task = input("enter the task")
        target = input("enter the target")
        pp = "TASK "+str(i)+' :'
        qq = "TARGET "+str(i)+" :"
         
        f1.write(pp)
        f1.write(task)
        f1.write('\n')
        f1.write(qq)
        f1.write(target)
        f1.write('\n')
        print("Do u want to stop press space bar otherwise enter")
        s = input()
        if s == ' ':
            break
    f1.close()
 
 
def task_update(username):
    username = username+" TASK.txt"
    print("Please enter the tasks which are completed ")
    task_completed = input()
     
    print("Enter task which are still not started by you")
    task_not_started = input()
     
    print("Enter task which you are doing")
    task_ongoing = input()
     
    fw = open(username, 'a')
    DT = str(datetime.datetime.now())
    fw.write(DT)
    fw.write("\n")
    fw.write("COMPLETED TASK \n")
    fw.write(task_completed)
    fw.write("\n")
    fw.write("ONGOING TASK \n")
    fw.write(task_ongoing)
    fw.write("\n")
    fw.write("NOT YET STARTED\n")
    fw.write(task_not_started)
    fw.write("\n")
 
 
def task_update_viewer(username):
    ussnm = username+" TASK.txt"
    o = open(ussnm, 'r')
    print(o.read())
    o.close()
 
 
if __name__ == '__main__':
    print("WELCOME TO ANURAG`S TASK MANAGER")
    print("sir are you new to this software")
    a = int(input("Type 1 if new otherwise press 0 ::"))
    if a == 1:
        signup()
    elif a == 0:
        login()
    else:
        print("You have provided wrong input !")


  • 第 4 步:现在我们将创建一个“user_information”函数,该函数将从“signup”函数中获取数据并制作一个文本文件来保存用户数据。下面的代码将显示事情将如何进行。

Python3

# pssd means password, ussnm is username
def user_information(ussnm, pssd):
    name = input("enter your name please: ")
    address = input("your address")
    age = input("Your age please")
    ussnm_ = ussnm+" task.txt"
     
    f = open(ussnm_, 'a')
    f.write(pssd)
    f.write("\nName: ")
    f.write(name)
    f.write('\n')
    f.write("Address :")
 
    f.write(address)
    f.write('\n')
    f.write("Age :")
    f.write(age)
    f.write('\n')
    f.close()
 
 
def signup():
    print("Please enter the username by which you\
    wanna access your account")
    username = input("please enter here:  ")
    password = input("Enter a password:  ")
    user_information(username, password)
  • 第 5 步:一旦user_information函数创建了文本文件,就该编写登录函数了。登录函数将获取用户名并要求输入与其连接的密码。一旦用户输入密码,该函数将检查保存在文本文件中的密码是否与输入的相同。代码可以解释的更准确,

Python3

def login():
    print("Please enter your username ")
    user_nm = input("Enter here: ")
     
    # Password as entered while logging in
    pssd_wr = (input("enterr the password"))+'\n'
    try:
        usernm = user_nm+" task.txt"
        f_ = open(usernm, 'r')
         
        # variable 'k' contains the password as saved
        # in the file
        k = f_.readlines(0)[0]
        f_.close()
         
         # Checking if the Password entered is same as
         # the password saved while signing in
        if pssd_wr == k:
            print(
                "1--to view your data \n2--To add task \n3--Update\
                task status \n4--View task status")
            a = input()
        else:
            print("SIR YOUR PASSWORD OR USERNAME IS WRONG , Plz enter Again")
            login()
    except Exception as e:
        print(e)
        login()
  • 第 6 步:在这一步中,我们将确保在用户登录后,我们可以要求他/她登录到他们的帐户。这可以通过在登录函数末尾调用登录函数来完成。因此,登录函数看起来像

Python3

def signup():
    print("Please enter the username by which you wanna access your account")
    username = input("please enter here:  ")
    password = input("Enter a password:  ")
    user_information(username, password)
    print("Sir please proceed towards log in")
    login()
  • 第7步:让我们完成“登录”块中提到的四个重要功能。即,查看数据的函数、向数据添加任务的函数、更新任务状态的函数和查看任务状态的函数。在这一步中,我们将在输入用户的需求,即变量a的输入后,通过完成if-else部分来完成'login'函数。参考下面的代码:

Python3

def login():
    print("Please enter your username ")
    user_nm = input("Enter here: ")
     
    # Password as entered while logging in
    pssd_wr = (input("enterr the password"))+'\n'
    try:
        usernm = user_nm+" task.txt"
        f_ = open(usernm, 'r')
         
        # variable 'k' contains the password as
        # saved in the file
        k = f_.readlines(0)[0]
        f_.close()
         
         # Checking if the Password entered is same
         # as the password saved while signing in
        if pssd_wr == k:
            print(
                "1--to view your data \n2--To add task \n3--Update\
                task \n4--VIEW TASK STATUS")
            a = input()
             
            if a == '1':
                view_data(usernm)
            elif a == '2':
                # add task
                task_information(usernm)
            elif a == '3':
                task_update(user_nm)
            elif a == '4':
                task_update_viewer(user_nm)
            else:
                print("Wrong input ! ")
        else:
            print("SIR YOUR PASSWORD OR USERNAME IS WRONG")
            login()
 
    except Exception as e:
        print(e)
        login()
 
 
def view_data(username):
    pass
 
def task_information(username):
    pass
 
def task_update(username):
    pass
 
def task_update_viewer(username):
    pass


如您所见, pass 命令用于让我们在没有函数体的情况下编写函数名和参数,并防止在代码编辑器中出现错误消息。

  • 第 8 步:让我们对视图数据块进行编码。

Python3

def view_data(username):
    ff = open(username, 'r')
    print(ff.read())
    ff.close()
  • 第 9 步:要对任务信息块进行编码,我们需要牢记Python中文本处理的基本概念。我们将询问用户他/她想要添加多少任务,并且根据他的意愿,我们将循环多次并要求他输入他/她想要完成的任务和目标。

Python3

def task_information(username):
    print("Sir enter n.o of task you want to ADD")
    j = int(input())
    f1 = open(username, 'a')
     
    for i in range(1, j+1):
        task = input("enter the task")
        target = input("enter the target")
        pp = "TASK "+str(i)+' :'
        qq = "TARGET "+str(i)+" :"
         
        f1.write(pp)
        f1.write(task)
        f1.write('\n')
        f1.write(qq)
        f1.write(target)
        f1.write('\n')
         
        print("Do u want to stop press space bar otherwise enter")
        s = input()
        if s == ' ':
            break
    f1.close()

请注意,我们添加了一条消息,如果用户想在他希望的次数之前停止添加任务,那么他将有机会。这使得该程序非常用户友好。

  • 第 10 步:更新任务状态与Python中的文本处理概念类似。我们将要做的是,我们将保存哪些任务编号已完成,哪些正在进行中,哪些尚未开始,并带有日期时间戳。文本文件的那部分看起来像,
2021-06-01 14:44:02.851506
COMPLETED TASK  
1,3,4
ONGOING TASK  
2
NOT YET STARTED
5

Python3

def task_update(username):
    username = username+" TASK.txt"
    print("Please enter the tasks which are completed ")
     
    task_completed = input()
    print("Enter task which are still not started by you")
     
    task_not_started = input()
    print("Enter task which you are doing")
     
    task_ongoing = input()
    fw = open(username, 'a')
    DT = str(datetime.datetime.now())
     
    fw.write(DT)
    fw.write("\n")
    fw.write("COMPLETED TASK \n")
    fw.write(task_completed)
    fw.write("\n")
    fw.write("ONGOING TASK \n")
    fw.write(task_ongoing)
    fw.write("\n")
    fw.write("NOT YET STARTED\n")
    fw.write(task_not_started)
    fw.write("\n")
  • 第 11 步:现在我们剩下任务更新查看器函数。该函数与“view_data”函数一样简单。

Python3

def task_update_viewer(username):
    ussnm = username+" TASK.txt"
    o = open(ussnm, 'r')
    print(o.read())
    o.close()

这将结束程序。但在我们结束之前,最重要的任务仍然是编写 main函数并从 main函数本身控制程序的命令流。

  • 第12步:主要函数。

Python3

if __name__ == '__main__':
    print("WELCOME TO ANURAG`S TASK MANAGER")
    print("sir are you new to this software")
    a = int(input("Type 1 if new otherwise press 0 ::"))
     
    if a == 1:
        signup()
    elif a == 0:
        login()
    else:
        print("You have provided wrong input !")

这标志着代码的结束。你应该尝试对这段代码做适当的修改,让软件变得更漂亮。

源代码:

Python3

import datetime
 
# pssd means password, ussnm is username
def user_information(ussnm, pssd): 
    name = input("enter your name please: ")
    address = input("your address")
    age = input("Your age please")
    ussnm_ = ussnm+" task.txt"
    f = open(ussnm_, 'a')
    f.write(pssd)
    f.write("\nName: ")
    f.write(name)
    f.write('\n')
    f.write("Address :")
 
    f.write(address)
    f.write('\n')
    f.write("Age :")
    f.write(age)
    f.write('\n')
    f.close()
 
 
def signup():
    print("Please enter the username by which you wanna access your account")
    username = input("please enter here:  ")
    password = input("Enter a password:  ")
    user_information(username, password)
    print("Sir please proceed towards log in")
    login()
 
 
def login():
    print("Please enter your username ")
    user_nm = input("Enter here: ")
     
    # Password as entered while logging in
    pssd_wr = (input("enterr the password"))+'\n'
    try:
        usernm = user_nm+" task.txt"
        f_ = open(usernm, 'r')
         
        # variable 'k' contains the password as saved
        # in the file
        k = f_.readlines(0)[0]
        f_.close()
         
        # Checking if the Password entered is same as
        # the password saved while signing in
        if pssd_wr == k:  
            print(
                "1--to view your data \n2--To add task \n3--Update\
                task \n4--VIEW TASK STATUS")
            a = input()
             
            if a == '1':
                view_data(usernm)
            elif a == '2':
                # add task
                task_information(usernm)
            elif a == '3':
                task_update(user_nm)
            elif a == '4':
                task_update_viewer(user_nm)
            else:
                print("Wrong input ! bhai dekh kr input dal")
        else:
            print("SIR YOUR PASSWORD OR USERNAME IS WRONG")
            login()
 
    except Exception as e:
        print(e)
        login()
 
 
def view_data(username):
    ff = open(username, 'r')
    print(ff.read())
    ff.close()
 
 
def task_information(username):
    print("Sir enter n.o of task you want to ADD")
    j = int(input())
    f1 = open(username, 'a')
     
    for i in range(1, j+1):
        task = input("enter the task")
        target = input("enter the target")
        pp = "TASK "+str(i)+' :'
        qq = "TARGET "+str(i)+" :"
         
        f1.write(pp)
        f1.write(task)
        f1.write('\n')
        f1.write(qq)
        f1.write(target)
        f1.write('\n')
        print("Do u want to stop press space bar otherwise enter")
        s = input()
        if s == ' ':
            break
    f1.close()
 
 
def task_update(username):
    username = username+" TASK.txt"
    print("Please enter the tasks which are completed ")
    task_completed = input()
     
    print("Enter task which are still not started by you")
    task_not_started = input()
     
    print("Enter task which you are doing")
    task_ongoing = input()
     
    fw = open(username, 'a')
    DT = str(datetime.datetime.now())
    fw.write(DT)
    fw.write("\n")
    fw.write("COMPLETED TASK \n")
    fw.write(task_completed)
    fw.write("\n")
    fw.write("ONGOING TASK \n")
    fw.write(task_ongoing)
    fw.write("\n")
    fw.write("NOT YET STARTED\n")
    fw.write(task_not_started)
    fw.write("\n")
 
 
def task_update_viewer(username):
    ussnm = username+" TASK.txt"
    o = open(ussnm, 'r')
    print(o.read())
    o.close()
 
 
if __name__ == '__main__':
    print("WELCOME TO ANURAG`S TASK MANAGER")
    print("sir are you new to this software")
    a = int(input("Type 1 if new otherwise press 0 ::"))
    if a == 1:
        signup()
    elif a == 0:
        login()
    else:
        print("You have provided wrong input !")

输出:

查看登录部分对用户的显示方式:

登录用户将操作此软件:

现实生活中的项目应用

  • 这对于学生记下他的任务或家庭作业及其完成期限非常有帮助。
  • 这对于学习者记下要学习的内容和资源非常有帮助。