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