Amazing-Python-Scripts

Форк
0
116 строк · 4.7 Кб
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)+"    " +
28
                    time+"                   "+work)
29
    elif n == 2:
30
        if (no_of_items <= 0):
31
            print("There is no item in the list kindly add some items")
32
        else:
33
            print("____________________________________________________________")
34
            print("Your Current List: ")
35
            todo = []
36
            with open('./TODO (CLI-VER)/todolist.txt') as f:
37
                for i in f.readlines():
38
                    print(i)
39
                    todo.append(i)
40
            print("____________________________________________________________")
41
            print("Enter the position of the item you want to delete : ")
42
            pos = int(input())
43
            if (pos <= 0):
44
                print("Please enter a valid position")
45
            elif (pos > (no_of_items)):
46
                print("Please enter the position <= {}".format(no_of_items))
47
            else:
48

49
                todo.pop(pos+1)
50
                no_of_items -= 1
51
                if (no_of_items <= 0):
52
                    print("Congratulations your todo list is empty!")
53

54
                with open('./TODO (CLI-VER)/todolist.txt', 'w') as f:
55
                    for i in range(len(todo)):
56
                        if i >= (pos+1):
57
                            f.write(str(pos)+todo[i][1:])
58
                            pos += 1
59
                        else:
60
                            f.write(todo[i])
61

62
    elif n == 3:
63
        print("____________________________________________________________")
64
        print("Your Current List: ")
65
        todo = []
66
        with open('./TODO (CLI-VER)/todolist.txt') as f:
67
            for i in f.readlines():
68
                print(i)
69
                todo.append(i)
70
        print("____________________________________________________________")
71
        print("Enter the position of the items you want to update : ")
72
        pos = int(input())
73
        if (pos <= 0):
74
            print("Please enter a valid position")
75
        elif (pos > (no_of_items)):
76
            print("Please enter the position <= {}".format(no_of_items))
77
        else:
78
            print("What you want to update : ")
79
            print("Press 1: Time\nPress 2: Work")
80
            choice = int(input())
81
            if choice == 1:
82
                print("Enter your updated time :")
83
                time = input()
84
                p = todo[pos+1].index(":")
85
                y = 0
86
                with open('./TODO (CLI-VER)/todolist.txt', 'w') as f:
87
                    for i in range(len(todo)):
88
                        if i == pos+1:
89
                            f.write(str(pos)+"    "+time+"" +
90
                                    ''.join(todo[pos+1][p+3:]))
91
                        else:
92
                            f.write(todo[i])
93
            elif choice == 2:
94
                print("Enter your updated work :")
95
                work = input()
96
                p = todo[pos+1].index(":")
97
                y = 0
98
                with open('./TODO (CLI-VER)/todolist.txt', 'w') as f:
99
                    for i in range(len(todo)):
100
                        if i == pos+1:
101
                            f.write(
102
                                str(pos)+"    "+''.join(todo[pos+1][p-2:p+3])+"                   "+work)
103
                        else:
104
                            f.write(todo[i])
105
    elif n == 4:
106
        print("Your Current List: ")
107
        todo = []
108
        print("____________________________________________________________")
109
        with open('./TODO (CLI-VER)/todolist.txt') as f:
110
            for i in f.readlines():
111
                print(i)
112
                todo.append(i)
113
        print("____________________________________________________________")
114
    print("Press 1: Add Item \nPress 2: Delete the Item\nPress 3: Update item\nPress 4:Display Items\nPress 5:Exit")
115
    n = int(input())
116
print("Thank you for using our application")
117

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.