CI / test-and-package (push) Successful in 37s
- ntfy.py: send_meal_reminder() with Home/Out HTTP action buttons, test helper - models.py: new columns ntfy_url, ntfy_token, callback_token on users table - meals.py: /api/ntfy-callback (public, token-authenticated), /ntfy-settings, /ntfy-test - app.py: flask send-reminders CLI command (cron-schedulable) - Dashboard: ntfy config form in Account Settings - i18n: translations for all ntfy strings (en/fr/de) - Dockerfile: include ntfy.py in COPY - tests: 15 new tests covering callback, settings, and auth - docs: updated AGENTS.md and doc/index.md
67 lines
2.4 KiB
Python
67 lines
2.4 KiB
Python
"""Meal Tracker — Flask application entry point."""
|
|
|
|
import os
|
|
from datetime import date
|
|
|
|
import click
|
|
from flask import Flask
|
|
|
|
from models import init_db, get_users_with_ntfy, get_all_households
|
|
from auth import auth_bp
|
|
from meals import meals_bp
|
|
from i18n import init_i18n
|
|
from ntfy import send_meal_reminder
|
|
|
|
|
|
def create_app() -> Flask:
|
|
app = Flask(__name__)
|
|
app.secret_key = os.environ.get("SECRET_KEY", "dev-secret-change-me")
|
|
|
|
app.register_blueprint(auth_bp)
|
|
app.register_blueprint(meals_bp)
|
|
|
|
with app.app_context():
|
|
init_db()
|
|
|
|
init_i18n(app)
|
|
|
|
# ── CLI commands ──
|
|
@app.cli.command("send-reminders")
|
|
@click.option("--date", default=None, help="Date to send reminders for (YYYY-MM-DD, default: today)")
|
|
@click.option("--meal", default="both", type=click.Choice(["lunch", "dinner", "both"]),
|
|
help="Which meal to send reminders for (default: both)")
|
|
@click.option("--base-url", default=None, help="Base URL of the app (default: $APP_BASE_URL or http://localhost:5000)")
|
|
def send_reminders_command(date, meal, base_url):
|
|
"""Send ntfy meal reminders to all users who have ntfy configured."""
|
|
target_date = date and __import__("datetime").datetime.strptime(date, "%Y-%m-%d").date() or date.today()
|
|
app_base_url = base_url or os.environ.get("APP_BASE_URL", "http://localhost:5000")
|
|
|
|
meal_types = ["lunch", "dinner"] if meal == "both" else [meal]
|
|
total_sent = 0
|
|
|
|
for household in get_all_households():
|
|
for user in get_users_with_ntfy(household["id"]):
|
|
for mt in meal_types:
|
|
ok = send_meal_reminder(
|
|
ntfy_url=user["ntfy_url"],
|
|
ntfy_token=user["ntfy_token"],
|
|
callback_token=user["callback_token"],
|
|
meal_type=mt,
|
|
for_date=target_date,
|
|
app_base_url=app_base_url,
|
|
)
|
|
if ok:
|
|
total_sent += 1
|
|
click.echo(f" ✓ {user['username']} ({mt})")
|
|
else:
|
|
click.echo(f" ✗ {user['username']} ({mt}) — failed")
|
|
|
|
click.echo(f"\nSent {total_sent} reminder(s) for {target_date.isoformat()}.")
|
|
|
|
return app
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app = create_app()
|
|
app.run(host="0.0.0.0", port=5000, debug=True)
|