fixed reminder

This commit is contained in:
2026-06-11 12:34:35 +03:00
parent 41cbef61a9
commit 66e1b0e29e
7 changed files with 104 additions and 19 deletions
+52
View File
@@ -0,0 +1,52 @@
"""Идемпотентно добавляет ежегодные напоминания: ДР 12 мая и Новый год."""
from sqlalchemy import select
from app.db.base import SessionLocal
from app.db.models import Reminder
from app.reminders.service import RECURRENCE_YEARLY, RemindersService
DEFAULTS = (
{
"title": "День рождения",
"due_at": "2027-05-12T09:00:00+03:00",
"notes": "С днём рождения!",
"all_day": True,
"recurrence": RECURRENCE_YEARLY,
},
{
"title": "Новый год",
"due_at": "2026-12-31T23:55:00+03:00",
"notes": "С наступающим Новым годом!",
"all_day": False,
"recurrence": RECURRENCE_YEARLY,
},
)
def main() -> None:
db = SessionLocal()
try:
service = RemindersService(db)
for item in DEFAULTS:
exists = db.scalar(
select(Reminder.id)
.where(
Reminder.title == item["title"],
Reminder.recurrence == RECURRENCE_YEARLY,
Reminder.enabled.is_(True),
)
.limit(1)
)
if exists:
print(f"skip: {item['title']} (id={exists})")
continue
result = service.create(**item)
reminder = result["reminder"]
print(f"created: {reminder['title']} · {reminder['due_at_local']} · yearly")
finally:
db.close()
if __name__ == "__main__":
main()