-
Notifications
You must be signed in to change notification settings - Fork 57
/
notes_projects.py
141 lines (128 loc) · 4.43 KB
/
notes_projects.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import os
def remove_note(note_num: int):
new_file = open("data.txt", "r")
lines = new_file.readlines()
new_file.close()
file_path = 'data.txt'
for line in lines:
line = line.split('|')
wanted_index_remove = note_num - 1
for index in range(len(line)):
if index == wanted_index_remove:
print(f"You deleted {line[index]}")
line.pop(index)
new_file = open("data.txt", "w")
line = [str(x) for x in line]
new_list_to_save = '|'.join(line)
new_file.write(new_list_to_save)
break
def add_note(file_name: str, note: str, title: str):
file_path = 'data.txt'
new_file = open("data.txt", "a")
if os.stat(file_path).st_size == 0:
new_file.write(f'{title}-' + note)
else:
new_file.write('|' + f'{title}-' + note)
new_file.close()
def view_notes():
new_file = open("data.txt", "r")
lines = new_file.readlines()
file_path = "data.txt"
if os.stat(file_path).st_size == 0:
print("You don't have any notes.")
else:
for line in lines:
line = line.split('|')
print('This is all of your notes:')
counter = 1
for element in line:
element = element.split('-')
print(f'{counter}. ' + element[0])
counter += 1
def see_specific_note(given_note: str):
if given_note.lower() == 'n':
pass
else:
given_note = int(given_note)
new_file = open("data.txt", "r")
lines = new_file.readlines()
file_path = "data.txt"
for line in lines:
line = line.split('|')
element = line[given_note - 1].split('-')
print(f'Your note: {element[1]}')
def search_notes(note: str):
any_notes = False
store_found_notes = []
new_file = open("data.txt", "r")
lines = new_file.readlines()
for line in lines:
line = line.split('|')
for element in line:
if note in element.lower():
store_found_notes.append(element)
any_notes = True
else:
if any_notes:
pass
else:
any_notes = False
if any_notes:
print("All notes that you are looking for:")
for found_note in store_found_notes:
print(found_note)
else:
print("It look's like you don't have similar notes.")
new_file.close()
print('-----> Note Project <-----')
print()
print('1. Remove note from storage.')
print('2. Add note to storage.')
print('3. View all notes in storage.')
print('4. Search for note in storage.')
# print('5. Edit note.')
print('5. If you want to quit.')
print()
print('-----------------------------')
user_input = input('What do you want to do? ')
while True:
# remove
if '1' in user_input:
file_path_name = "data.txt"
if os.stat(file_path_name).st_size == 0:
print("You don't have any notes.")
else:
view_notes()
value = int(input("Choose which note to delete: "))
remove_note(value)
# Add
elif '2' in user_input:
title_name = input("Choose a title for your note: ")
value = input("Write what you want to add: ")
add_note("data.txt", value, title_name)
# View
elif '3' in user_input:
view_notes()
file_path_name = "data.txt"
if os.stat(file_path_name).st_size == 0:
pass
else:
specific_note = input('Do you want to see a note in detail?("n" for no) ')
see_specific_note(specific_note)
# Search
elif '4' in user_input:
file_path_name = "data.txt"
if os.stat(file_path_name).st_size == 0:
print("You don't have any notes.")
else:
value = input("Write what you want to search for: ")
while len(value) < 2:
print('You should write at least two letters.')
value = input("Write what you want to search for: ")
search_notes(value)
# Quit
elif '5' in user_input:
break
print('-----------------------------')
user_input = input('What do you want to do? ')
print("Thanks for using our app.")