get_nutrition_day
Retrieve detailed daily nutrition data including meals and food items to support fitness tracking and dietary analysis.
Instructions
Get a complete nutrition day with meals and items.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| date | Yes |
Implementation Reference
- src/main.py:492-536 (handler)The tool 'get_nutrition_day' is defined using the '@app.tool()' decorator. It fetches nutrition data for a specific date from the SQLite database, including meals and their constituent items, calculates the nutritional totals for the meals and the day, and returns the structured data.
@app.tool() def get_nutrition_day(date: str) -> dict[str, Any | None]: """Get a complete nutrition day with meals and items.""" date = _ensure_date(date) conn = get_connection() cursor = conn.cursor() cursor.execute("SELECT * FROM nutrition_days WHERE date = ?", (date,)) day_row = cursor.fetchone() if not day_row: conn.close() return {"day": None} day = _row_to_dict(day_row) cursor.execute("SELECT * FROM meals WHERE day_id = ? ORDER BY order_index", (day["id"],)) meals = [] for meal_row in cursor.fetchall(): meal = _row_to_dict(meal_row) cursor.execute("SELECT * FROM meal_items WHERE meal_id = ?", (meal["id"],)) items = [_row_to_dict(r) for r in cursor.fetchall()] # Compute totals totals = { "calories": sum(i["calories"] for i in items), "protein_g": sum(i["protein_g"] for i in items), "carbs_g": sum(i["carbs_g"] for i in items), "fats_g": sum(i["fats_g"] for i in items), "fiber_g": sum(i["fiber_g"] for i in items), } meal["items"] = items meal["totals"] = totals meals.append(meal) # Compute day totals day["totals"] = { "calories": sum(m["totals"]["calories"] for m in meals), "protein_g": sum(m["totals"]["protein_g"] for m in meals), "carbs_g": sum(m["totals"]["carbs_g"] for m in meals), "fats_g": sum(m["totals"]["fats_g"] for m in meals), "fiber_g": sum(m["totals"]["fiber_g"] for m in meals), } day["meals"] = meals conn.close() return {"day": day}