Add cron container and per-household timezone for auto-reminders
CI / test-and-package (push) Successful in 36s

- docker-compose.yml: meal-cron service loops send_reminders_cron.py every 60s
- send_reminders_cron.py: checks each household's local time, sends ntfy
  reminders at 10:00 (lunch) and 16:00 (dinner), guarded against duplicates
- models.py: timezone, last_lunch_reminder, last_dinner_reminder on households
- meals.py: /admin/timezone route for admins to set household timezone
- dashboard: timezone selector (20 common zones) in Account Settings
- i18n: 5 new translation keys for timezone strings
- Dockerfile: copy send_reminders_cron.py
- tests: 4 new timezone tests (admin set, non-admin denied, default UTC, auth)
- docs: updated AGENTS.md
This commit is contained in:
agentbox
2026-08-01 06:23:33 +00:00
parent 3681f9dfce
commit 2cd435daf2
9 changed files with 248 additions and 2 deletions
+24
View File
@@ -76,6 +76,15 @@ def init_db() -> None:
if "callback_token" not in cols:
db.execute("ALTER TABLE users ADD COLUMN callback_token TEXT DEFAULT ''")
# Migration: add timezone and reminder tracking to households
hh_cols = [r["name"] for r in db.execute("PRAGMA table_info(households)").fetchall()]
if "timezone" not in hh_cols:
db.execute("ALTER TABLE households ADD COLUMN timezone TEXT DEFAULT 'UTC'")
if "last_lunch_reminder" not in hh_cols:
db.execute("ALTER TABLE households ADD COLUMN last_lunch_reminder TEXT DEFAULT ''")
if "last_dinner_reminder" not in hh_cols:
db.execute("ALTER TABLE households ADD COLUMN last_dinner_reminder TEXT DEFAULT ''")
# ── Households ────────────────────────────────────────────────────────────────
@@ -130,6 +139,21 @@ def delete_household(household_id: int) -> None:
db.execute("DELETE FROM households WHERE id = ?", (household_id,))
def set_household_timezone(household_id: int, timezone: str) -> None:
"""Update the timezone for a household."""
with get_db() as db:
db.execute("UPDATE households SET timezone = ? WHERE id = ?",
(timezone, household_id))
def update_reminder_sent(household_id: int, meal_type: str, date_str: str) -> None:
"""Mark a reminder as sent for the given meal and date."""
col = "last_lunch_reminder" if meal_type == "lunch" else "last_dinner_reminder"
with get_db() as db:
db.execute(f"UPDATE households SET {col} = ? WHERE id = ?",
(date_str, household_id))
# ── Users ─────────────────────────────────────────────────────────────────────
def get_user_by_id(user_id: int) -> dict | None: