Files
Home_assistant/backend/scripts/seed_holiday_reminders.py
2026-06-11 12:34:35 +03:00

53 lines
1.5 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Идемпотентно добавляет ежегодные напоминания: ДР 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()