-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_record.py
More file actions
29 lines (23 loc) · 827 Bytes
/
Copy pathadd_record.py
File metadata and controls
29 lines (23 loc) · 827 Bytes
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
import os
from rich.console import Console
from rich import print
from SQL import SessionLocal, Record
console = Console()
def add_record(user_id):
try:
os.system('cls')
console.print("--- Новая запись ---", justify="center")
title = input("\nЗаголовок: ")
content = input("Текст записи:\n")
session = SessionLocal()
try:
new_rec = Record(title=title, content=content, user_id=user_id)
session.add(new_rec)
session.commit()
print("[green]\nЗапись успешно добавлена ![/]")
except Exception as e:
print(f"[red]Ошибка: {e}[/]")
finally:
session.close()
except KeyboardInterrupt:
pass