|
| 1 | +#Check for the existence of file |
| 2 | +no_of_items=0 |
| 3 | +try: |
| 4 | + f=open("./TODO (CLI-VER)/todolist.txt") |
| 5 | + p=0 |
| 6 | + for i in f.readlines():#Counting the number of items if the file exists already |
| 7 | + p+=1 |
| 8 | + no_of_items=p-2 |
| 9 | +except: |
| 10 | + f=open("./TODO (CLI-VER)/todolist.txt",'w') |
| 11 | + f.write("_________TODO LIST__________\n") |
| 12 | + f.write(" TIME WORK") |
| 13 | +finally: |
| 14 | + f.close() |
| 15 | +#Todo list |
| 16 | +print("Press 1: Add Item \nPress 2: Delete Item \nPress 3: Update item \nPress 4: Display Items\nPress 5: Exit") |
| 17 | +n=int(input()) |
| 18 | +while n==1 or n==2 or n==3 or n==4: |
| 19 | + if n==1: |
| 20 | + todo=[] |
| 21 | + print("Enter the time in HH:MM format(24 hours format)") |
| 22 | + time=input() |
| 23 | + print("Enter your Work") |
| 24 | + work=input() |
| 25 | + no_of_items+=1 |
| 26 | + with open('./TODO (CLI-VER)/todolist.txt','a') as f: |
| 27 | + f.write("\n"+str(no_of_items)+" "+time+" "+work) |
| 28 | + elif n==2: |
| 29 | + if(no_of_items<=0): |
| 30 | + print("There is no item in the list kindly add some items") |
| 31 | + else: |
| 32 | + print("____________________________________________________________") |
| 33 | + print("Your Current List: ") |
| 34 | + todo=[] |
| 35 | + with open('./TODO (CLI-VER)/todolist.txt') as f: |
| 36 | + for i in f.readlines(): |
| 37 | + print(i) |
| 38 | + todo.append(i) |
| 39 | + print("____________________________________________________________") |
| 40 | + print("Enter the position of the item you want to delete : ") |
| 41 | + pos=int(input()) |
| 42 | + if(pos<=0): |
| 43 | + print("Please enter a valid position") |
| 44 | + elif (pos>(no_of_items)): |
| 45 | + print("Please enter the position <= {}".format(no_of_items)) |
| 46 | + else: |
| 47 | + |
| 48 | + todo.pop(pos+1) |
| 49 | + no_of_items-=1 |
| 50 | + if(no_of_items<=0): |
| 51 | + print("Congratulations your todo list is empty!") |
| 52 | + |
| 53 | + with open('./TODO (CLI-VER)/todolist.txt','w') as f: |
| 54 | + for i in range(len(todo)): |
| 55 | + if i>=(pos+1): |
| 56 | + f.write(str(pos)+todo[i][1:]) |
| 57 | + pos+=1 |
| 58 | + else: |
| 59 | + f.write(todo[i]) |
| 60 | + |
| 61 | + elif n==3: |
| 62 | + print("____________________________________________________________") |
| 63 | + print("Your Current List: ") |
| 64 | + todo=[] |
| 65 | + with open('./TODO (CLI-VER)/todolist.txt') as f: |
| 66 | + for i in f.readlines(): |
| 67 | + print(i) |
| 68 | + todo.append(i) |
| 69 | + print("____________________________________________________________") |
| 70 | + print("Enter the position of the items you want to update : ") |
| 71 | + pos=int(input()) |
| 72 | + if(pos<=0): |
| 73 | + print("Please enter a valid position") |
| 74 | + elif (pos>(no_of_items)): |
| 75 | + print("Please enter the position <= {}".format(no_of_items)) |
| 76 | + else: |
| 77 | + print("What you want to update : ") |
| 78 | + print("Press 1: Time\nPress 2: Work") |
| 79 | + choice=int(input()) |
| 80 | + if choice==1: |
| 81 | + print("Enter your updated time :") |
| 82 | + time=input() |
| 83 | + p=todo[pos+1].index(":") |
| 84 | + y=0 |
| 85 | + with open('./TODO (CLI-VER)/todolist.txt','w') as f: |
| 86 | + for i in range(len(todo)): |
| 87 | + if i==pos+1: |
| 88 | + f.write(str(pos)+" "+time+""+''.join(todo[pos+1][p+3:])) |
| 89 | + else: |
| 90 | + f.write(todo[i]) |
| 91 | + elif choice==2: |
| 92 | + print("Enter your updated work :") |
| 93 | + work=input() |
| 94 | + p=todo[pos+1].index(":") |
| 95 | + y=0 |
| 96 | + with open('./TODO (CLI-VER)/todolist.txt','w') as f: |
| 97 | + for i in range(len(todo)): |
| 98 | + if i==pos+1: |
| 99 | + f.write(str(pos)+" "+''.join(todo[pos+1][p-2:p+3])+" "+work) |
| 100 | + else: |
| 101 | + f.write(todo[i]) |
| 102 | + elif n==4: |
| 103 | + print("Your Current List: ") |
| 104 | + todo=[] |
| 105 | + print("____________________________________________________________") |
| 106 | + with open('./TODO (CLI-VER)/todolist.txt') as f: |
| 107 | + for i in f.readlines(): |
| 108 | + print(i) |
| 109 | + todo.append(i) |
| 110 | + print("____________________________________________________________") |
| 111 | + print("Press 1: Add Item \nPress 2: Delete the Item\nPress 3: Update item\nPress 4:Display Items\nPress 5:Exit") |
| 112 | + n=int(input()) |
| 113 | +print("Thank you for using our application") |
0 commit comments