Initial commit: Cocina con Alma - Tandoor + public menu stack

This commit is contained in:
consultoria-as
2026-04-21 07:30:28 +00:00
commit 680aaf4924
9 changed files with 1230 additions and 0 deletions

12
menu-publico/Dockerfile Normal file
View File

@@ -0,0 +1,12 @@
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 5000
CMD ["gunicorn", "-w", "2", "-b", "0.0.0.0:5000", "app:app"]

119
menu-publico/app.py Normal file
View File

@@ -0,0 +1,119 @@
import os
import requests
from flask import Flask, render_template
from datetime import datetime, timedelta
from collections import defaultdict
app = Flask(__name__)
TANDOOR_URL = os.environ.get("TANDOOR_URL", "http://web_recipes:8080")
TANDOOR_API_TOKEN = os.environ.get("TANDOOR_API_TOKEN", "")
def get_meal_plan():
if not TANDOOR_API_TOKEN:
return None, "Todavía no se configuró el token de API. Tu madre debe crearlo desde el panel de Tandoor."
headers = {
"Authorization": f"Token {TANDOOR_API_TOKEN}",
"Content-Type": "application/json",
"Host": "tandoor.local",
}
# Obtener meal plan de los próximos 7 días
today = datetime.now().date()
end = today + timedelta(days=6)
params = {
"from_date": today.isoformat(),
"to_date": end.isoformat(),
}
try:
resp = requests.get(
f"{TANDOOR_URL}/api/meal-plan/",
headers=headers,
params=params,
timeout=10,
)
resp.raise_for_status()
data = resp.json()
# Tandoor devuelve paginación: { "count": ..., "results": [...] }
results = data.get("results", data) if isinstance(data, dict) else data
return results, None
except requests.exceptions.ConnectionError:
return None, "No se pudo conectar con Tandoor. ¿Está iniciado el servicio?"
except requests.exceptions.HTTPError as e:
if resp.status_code == 401:
return None, "Token de API inválido. Verificá la configuración."
return None, f"Error de API: {e}"
except Exception as e:
return None, f"Error inesperado: {e}"
def group_by_day(meal_plans):
days = defaultdict(list)
dias_semana = ["Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado", "Domingo"]
for item in meal_plans:
date_str = item.get("from_date") or item.get("to_date")
if not date_str:
continue
try:
d = datetime.fromisoformat(date_str).date()
except Exception:
continue
recipe = item.get("recipe")
title = None
image = None
if recipe:
title = recipe.get("name", "Sin nombre")
image = recipe.get("image")
else:
title = item.get("title", "Sin nombre")
meal_type = item.get("meal_type", {})
tipo = meal_type.get("name", "Menú") if meal_type else "Menú"
days[d.isoformat()].append({
"title": title,
"image": image,
"tipo": tipo,
"servings": item.get("servings", 1),
})
# Ordenar por fecha
sorted_days = []
today = datetime.now().date()
for i in range(7):
d = today + timedelta(days=i)
key = d.isoformat()
sorted_days.append({
"fecha": d,
"nombre_dia": dias_semana[d.weekday()],
"meals": days.get(key, []),
})
return sorted_days
@app.route("/")
def index():
meal_plans, error = get_meal_plan()
if error:
return render_template("index.html", error=error, days=[])
if not meal_plans:
return render_template(
"index.html",
error="No hay platos planificados para esta semana. Tu madre puede cargarlos desde el panel de Tandoor.",
days=[],
)
days = group_by_day(meal_plans)
return render_template("index.html", error=None, days=days)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)

View File

@@ -0,0 +1,4 @@
flask==3.0.3
requests==2.31.0
gunicorn==23.0.0
python-dateutil==2.9.0

View File

@@ -0,0 +1,163 @@
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Menú Semanal - Cocina con Alma</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: #fdf6f0;
color: #4a3b2a;
line-height: 1.6;
}
header {
background: #d35400;
color: white;
padding: 2rem 1rem;
text-align: center;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
header h1 { font-size: 1.8rem; margin-bottom: 0.3rem; }
header p { opacity: 0.95; font-size: 1rem; }
.container {
max-width: 900px;
margin: 0 auto;
padding: 1.5rem 1rem;
}
.error {
background: #fff3cd;
border: 1px solid #ffeaa7;
color: #856404;
padding: 1.2rem;
border-radius: 10px;
margin-bottom: 1.5rem;
text-align: center;
}
.day-card {
background: white;
border-radius: 14px;
padding: 1.2rem;
margin-bottom: 1.2rem;
box-shadow: 0 3px 12px rgba(0,0,0,0.06);
border-left: 5px solid #e67e22;
}
.day-title {
font-size: 1.25rem;
font-weight: 700;
color: #d35400;
margin-bottom: 0.8rem;
display: flex;
align-items: center;
gap: 0.5rem;
}
.day-title .date {
font-size: 0.85rem;
color: #888;
font-weight: 500;
}
.meal {
display: flex;
align-items: center;
gap: 1rem;
padding: 0.7rem 0;
border-bottom: 1px solid #f0e6dc;
}
.meal:last-child { border-bottom: none; }
.meal img {
width: 60px;
height: 60px;
object-fit: cover;
border-radius: 10px;
background: #eee;
flex-shrink: 0;
}
.meal .placeholder {
width: 60px;
height: 60px;
border-radius: 10px;
background: #f5e6d3;
display: flex;
align-items: center;
justify-content: center;
font-size: 1.5rem;
flex-shrink: 0;
}
.meal-info h3 {
font-size: 1.05rem;
color: #5d4037;
margin-bottom: 0.15rem;
}
.meal-info .tag {
display: inline-block;
font-size: 0.75rem;
background: #fdebd0;
color: #a0522d;
padding: 0.15rem 0.5rem;
border-radius: 20px;
font-weight: 600;
}
.empty-day {
color: #aaa;
font-style: italic;
padding: 0.5rem 0;
}
footer {
text-align: center;
padding: 2rem 1rem;
color: #aaa;
font-size: 0.85rem;
}
@media (max-width: 480px) {
header h1 { font-size: 1.4rem; }
.day-card { padding: 1rem; }
.meal img, .meal .placeholder { width: 48px; height: 48px; }
}
</style>
</head>
<body>
<header>
<h1>🍽️ Menú Semanal</h1>
<p>Consultá lo que preparamos esta semana</p>
</header>
<div class="container">
{% if error %}
<div class="error">
⚠️ {{ error }}
</div>
{% endif %}
{% for day in days %}
<div class="day-card">
<div class="day-title">
{{ day.nombre_dia }}
<span class="date">{{ day.fecha.strftime('%d/%m') }}</span>
</div>
{% if day.meals %}
{% for item in day.meals %}
<div class="meal">
{% if item.image %}
<img src="{{ item.image }}" alt="{{ item.title }}">
{% else %}
<div class="placeholder">🍲</div>
{% endif %}
<div class="meal-info">
<h3>{{ item.title }}</h3>
<span class="tag">{{ item.tipo }}</span>
</div>
</div>
{% endfor %}
{% else %}
<div class="empty-day">Sin platos planificados para este día.</div>
{% endif %}
</div>
{% endfor %}
</div>
<footer>
<p>Cocina con Alma • Consultas por WhatsApp o al pasar por el negocio</p>
</footer>
</body>
</html>