-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrones_notes_akud_v1.py
67 lines (56 loc) · 2.34 KB
/
drones_notes_akud_v1.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
import os
import json
from datetime import datetime
def save_note(model, note):
"""Сохранение заметки в файл"""
with open('notes.txt', 'a') as f:
note_data = {
'model': model,
'note': note,
'timestamp': datetime.now().strftime('%Y-%m-%d %H:%M:%S')
}
f.write(json.dumps(note_data) + '\n')
def load_notes():
"""Загрузка ранее сохраненных заметок из файла"""
if os.path.exists('notes.txt'):
notes = []
with open('notes.txt', 'r') as f:
for line in f:
try:
note = json.loads(line.strip())
notes.append(note)
except json.JSONDecodeError:
print(f"Ошибка декодирования JSON для строки: {line.strip()}")
return notes
return []
def display_notes(notes):
"""Отображение всех заметок"""
if notes:
print("nРанее сохраненные заметки:")
for idx, note in enumerate(notes, start=1):
print(f"{idx}.Модель БПЛА: {note['model']} Описание: {note['note']} (создано: {note['timestamp']})")
else:
print("Нет сохраненных заметок.")
def main():
print('Программа заметок о БПЛА')
while True:
print("\nМеню:")
print("1. Ввести новую заметку о БПЛА")
print("2. Просмотреть ранее сохраненные заметки")
print("3. Выход")
choice = input("Выберите опцию (1-3): ")
if choice == '1':
model = input("Введите модель БПЛА: ").strip()
note = input("Введите описание БПЛА: ").strip()
save_note(model, note)
print("Заметка сохранена.")
elif choice == '2':
notes = load_notes()
display_notes(notes)
elif choice == '3':
print("Рвбота завершена. Выход из программы.")
break
else:
print("Неверный ввод. Пожалуйста, выберите 1, 2 или 3.")
if __name__ == "__main__":
main()