Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# консольная записная книжка
main находится в app.py

## основное меню
1. - save note
2. - find and read note
3. - edit note
0. - exit

## возможности
* сохранение ID, названия и тела заметки с отметкой даты

* доступен поиск по ID, названию, тексту, дате

* корректировка заметок по ID
Binary file added __pycache__/delete_note.cpython-310.pyc
Binary file not shown.
Binary file modified __pycache__/edit_note.cpython-310.pyc
Binary file not shown.
Binary file modified __pycache__/main_menu.cpython-310.pyc
Binary file not shown.
Binary file modified __pycache__/read_note.cpython-310.pyc
Binary file not shown.
1 change: 0 additions & 1 deletion data.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{"id": 1, "note_title": "first", "note": "firstnote", "timemark": "2023-02-13"}
{"id": 2, "note_title": "1", "note": "qwewq", "timemark": "2023-02-13"}
{"id": 3, "note_title": "the second", "note": "ready steady go", "timemark": "2023-02-13"}
{"id": 4, "note_title": "third", "note": "go go go", "timemark": "2023-02-13"}
41 changes: 41 additions & 0 deletions delete_note.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import json

def delete_note():
user_input = ""
while not user_input.isdigit():
print ('input id of note for delete (must be integer) ->')
user_input = input ()
with open("data.json", "r") as file:
while True:
line = file.readline()
if not line:
print("нет такого id")
break
data = json.loads(line)
if (data['id'] == int(user_input)):
print(data['note_title'])
print(data['note'])
break
open('tmpdata.json', 'w').close()
with open('data.json', 'r') as file:
while True:
line = file.readline()
if not line:
break
data = json.loads(line)

if data['id'] != int(user_input):
with open('tmpdata.json', 'a') as tmpfile:
json.dump(data, tmpfile, ensure_ascii=False)
tmpfile.writelines('\n')
open('data.json', 'w').close()
with open('tmpdata.json', 'r') as file:
while True:
line = file.readline()
if not line:
break
data = json.loads(line)
with open('data.json', 'a') as newfile:
json.dump(data, newfile, ensure_ascii=False)
newfile.writelines('\n')

6 changes: 4 additions & 2 deletions edit_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
from save_note import save_note

def edit_note():
print ('input id of note for edit ->')
user_input = input ()
user_input = ""
while not user_input.isdigit():
print ('input id of note for edit ->')
user_input = input ()
with open("data.json", "r") as file:
while True:
line = file.readline()
Expand Down
6 changes: 5 additions & 1 deletion main_menu.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
from delete_note import delete_note
from edit_note import edit_note
from read_note import find_id_note, find_note_with_date, find_text_in_notes, find_title_note
from save_note import save_note
Expand All @@ -7,7 +8,8 @@ def main_menu():
while True:
print ('1 - save note')
print ('2 - find and read note')
print ('3 - edit note')
print ('3 - edit note by ID')
print ('4 - delete note by ID')
print ('0 - exit')
user_input = input ()

Expand All @@ -18,6 +20,8 @@ def main_menu():
find_note_menu()
case "3":
edit_note()
case "4":
delete_note()
case "0":
sys.exit()

Expand Down
26 changes: 17 additions & 9 deletions read_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

# ('1 - find id note')
def find_id_note():
print ('input id of note ->')
user_input = input ()
user_input = ""
while not user_input.isdigit():
print ('input id of note ->')
user_input = input ()
with open("data.json", "r") as file:
while True:
line = file.readline()
Expand All @@ -22,8 +24,10 @@ def find_id_note():

# ('2 - find title note')
def find_title_note():
print ('input title of notes')
user_input = input ()
user_input = ""
while not user_input.isdigit():
print ('input title of notes')
user_input = input ()
with open("data.json", "r") as file:
while True:
line = file.readline()
Expand All @@ -42,9 +46,11 @@ def find_title_note():
print ('finding complete')

# ('3 - find text in notes')
def find_text_in_notes():
print ('input text in notes')
user_input = input ()
def find_text_in_notes():
user_input = ""
while not user_input.isdigit():
print ('input text in notes')
user_input = input ()
with open("data.json", "r") as file:
while True:
line = file.readline()
Expand All @@ -65,8 +71,10 @@ def find_text_in_notes():
# ('4 - find note with date')

def find_note_with_date():
print ('input date of notes(..2023-02-09)')
user_input = input ()
user_input = ""
while not user_input.isdigit():
print ('input date of notes(..2023-02-09)')
user_input = input ()
with open("data.json", "r") as file:
while True:
line = file.readline()
Expand Down
3 changes: 2 additions & 1 deletion tmpdata.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
{"id": 1, "note_title": "first", "note": "firstnote", "timemark": "2023-02-13"}
{"id": 2, "note_title": "1", "note": "qwewq", "timemark": "2023-02-13"}
{"id": 3, "note_title": "the second", "note": "ready steady go", "timemark": "2023-02-13"}
{"id": 4, "note_title": "third", "note": "go go go", "timemark": "2023-02-13"}