refactor(bot): remove /all and station-specific commands

This commit is contained in:
dasemu committed 2026-03-17 17:46:42 +01:00
1 parent 5e2a22340f
commit 32d8b07786
2 files changed
+5 -106

No files matched your search

+5 -103
View File
@@ -1,14 +1,9 @@
""" """
Telegram bot for the ski predictor system. Telegram bot for the ski predictor system.
Serves published predictions for three ski stations in northern Spain: Reads forecasts from the ``current_forecasts`` / ``past_forecasts`` tables in
- Valgrande-Pajares (/pajares) SQLite and serves multi-station horizon commands for three ski stations in
- San Isidro (/sanisidro) northern Spain.
- Fuentes de Invierno (/fuentes)
The bot reads forecasts from the ``current_forecasts`` / ``past_forecasts``
tables in SQLite and supports both single-station queries and multi-station
horizon commands.
Usage: Usage:
Set the TELEGRAM_BOT_TOKEN environment variable and run: Set the TELEGRAM_BOT_TOKEN environment variable and run:
@@ -358,16 +353,6 @@ def format_daily_predictions(payload: dict[str, Any]) -> str:
return "\n\n".join(sections) return "\n\n".join(sections)
def _no_prediction_message(station_name: str) -> str:
"""Return a friendly error message when prediction data is unavailable."""
return (
f"Lo siento, no hay predicción disponible para <b>{station_name}</b> en este "
f"momento.\n\n"
f"<i>El pipeline de datos se ejecuta diariamente. "
f"Inténtalo de nuevo más tarde.</i>"
)
def _unavailable_message() -> str: def _unavailable_message() -> str:
"""Return a message when published predictions cannot be loaded at all.""" """Return a message when published predictions cannot be loaded at all."""
return ( return (
@@ -405,12 +390,8 @@ async def cmd_start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
text = ( text = (
"<b>¡Bienvenido al bot de predicción de estaciones de esquí!</b>\n\n" "<b>¡Bienvenido al bot de predicción de estaciones de esquí!</b>\n\n"
"Este bot te informa sobre la predicción vigente para tres " "Este bot te informa sobre la predicción vigente para tres "
"estaciones de esquí del norte de España.\n" "estaciones de esquí del norte de España: "
"Hasta las 10:00 muestra preferentemente la predicción del mismo " "Valgrande-Pajares, San Isidro y Fuentes de Invierno.\n\n"
"día; después, la del día siguiente.\n\n"
" - <b>Valgrande-Pajares</b>\n"
" - <b>San Isidro</b>\n"
" - <b>Fuentes de Invierno</b>\n\n"
"Las predicciones combinan reglas operacionales y modelos de " "Las predicciones combinan reglas operacionales y modelos de "
"aprendizaje automático basados en datos meteorológicos.\n\n" "aprendizaje automático basados en datos meteorológicos.\n\n"
"Escribe /help para ver los comandos disponibles." "Escribe /help para ver los comandos disponibles."
@@ -422,10 +403,6 @@ async def cmd_help(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""Handle the /help command with a list of available commands.""" """Handle the /help command with a list of available commands."""
text = ( text = (
"<b>Comandos disponibles:</b>\n\n" "<b>Comandos disponibles:</b>\n\n"
"/pajares — Predicción para Valgrande-Pajares\n"
"/sanisidro — Predicción para San Isidro\n"
"/fuentes — Predicción para Fuentes de Invierno\n"
"/all — Predicción vigente para las tres estaciones\n"
"/hoy — Predicción de hoy para las tres estaciones\n" "/hoy — Predicción de hoy para las tres estaciones\n"
"/manana — Predicción de mañana para las tres estaciones\n" "/manana — Predicción de mañana para las tres estaciones\n"
"/tresdias — Predicción de hoy y los dos días siguientes\n" "/tresdias — Predicción de hoy y los dos días siguientes\n"
@@ -435,45 +412,6 @@ async def cmd_help(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
await update.message.reply_text(text, parse_mode=ParseMode.HTML) await update.message.reply_text(text, parse_mode=ParseMode.HTML)
async def _send_station(
update: Update,
station_key: str,
) -> None:
"""Fetch and send the prediction for a single station.
Args:
update: Telegram Update object.
station_key: One of 'pajares', 'sanisidro', 'fuentes'.
"""
station_name = STATIONS[station_key]["name"]
predictions = load_predictions()
if predictions is None:
text = _unavailable_message()
await update.message.reply_text(text, parse_mode=ParseMode.HTML)
return
station_predictions = _extract_station_predictions(predictions)
station_pred = station_predictions.get(station_key)
if not station_pred:
logger.warning("No hay entrada de predicción para la estación '%s'", station_key)
text = _no_prediction_message(station_name)
await update.message.reply_text(text, parse_mode=ParseMode.HTML)
return
try:
text = format_station_prediction(
station_key,
station_pred,
predictions.get("prediction_date"),
)
except Exception as exc: # noqa: BLE001
logger.exception("Error al formatear la predicción para '%s': %s", station_key, exc)
text = _no_prediction_message(station_name)
await update.message.reply_text(text, parse_mode=ParseMode.HTML)
async def _send_prediction_day( async def _send_prediction_day(
update: Update, update: Update,
prediction_date: str, prediction_date: str,
@@ -527,38 +465,6 @@ async def _send_prediction_window(
) )
async def cmd_pajares(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""Handle the /pajares command — prediction for Valgrande-Pajares."""
logger.info("El usuario %s solicitó /pajares", update.effective_user.id)
await _send_station(update, "pajares")
async def cmd_sanisidro(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""Handle the /sanisidro command — prediction for San Isidro."""
logger.info("El usuario %s solicitó /sanisidro", update.effective_user.id)
await _send_station(update, "sanisidro")
async def cmd_fuentes(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""Handle the /fuentes command — prediction for Fuentes de Invierno."""
logger.info("El usuario %s solicitó /fuentes", update.effective_user.id)
await _send_station(update, "fuentes")
async def cmd_all(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""Handle the /all command — predictions for all three stations."""
logger.info("El usuario %s solicitó /all", update.effective_user.id)
predictions = load_predictions()
if predictions is None:
await update.message.reply_text(_unavailable_message(), parse_mode=ParseMode.HTML)
return
await update.message.reply_text(
format_daily_predictions(predictions),
parse_mode=ParseMode.HTML,
)
async def cmd_hoy(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: async def cmd_hoy(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""Handle the /hoy command — three-station prediction for today.""" """Handle the /hoy command — three-station prediction for today."""
logger.info("El usuario %s solicitó /hoy", update.effective_user.id) logger.info("El usuario %s solicitó /hoy", update.effective_user.id)
@@ -619,10 +525,6 @@ def create_bot_application(token: str | None = None) -> Application:
app.add_handler(CommandHandler("start", cmd_start)) app.add_handler(CommandHandler("start", cmd_start))
app.add_handler(CommandHandler("help", cmd_help)) app.add_handler(CommandHandler("help", cmd_help))
app.add_handler(CommandHandler("pajares", cmd_pajares))
app.add_handler(CommandHandler("sanisidro", cmd_sanisidro))
app.add_handler(CommandHandler("fuentes", cmd_fuentes))
app.add_handler(CommandHandler("all", cmd_all))
app.add_handler(CommandHandler("hoy", cmd_hoy)) app.add_handler(CommandHandler("hoy", cmd_hoy))
app.add_handler(CommandHandler("manana", cmd_manana)) app.add_handler(CommandHandler("manana", cmd_manana))
app.add_handler(CommandHandler("tresdias", cmd_tresdias)) app.add_handler(CommandHandler("tresdias", cmd_tresdias))
-3
View File
@@ -8,7 +8,6 @@ stations:
minimum_snow_depth: 30 # cm minimum_snow_depth: 30 # cm
max_km_skiable: 22.0 max_km_skiable: 22.0
url: "https://www.valgrande-pajares.com" url: "https://www.valgrande-pajares.com"
telegram_command: "/pajares"
webcams: webcams:
# infonieve.es embeds a timestamp in the filename for Pajares. # infonieve.es embeds a timestamp in the filename for Pajares.
# The collector resolves the current URL by scraping the page at runtime. # The collector resolves the current URL by scraping the page at runtime.
@@ -33,7 +32,6 @@ stations:
minimum_snow_depth: 30 minimum_snow_depth: 30
max_km_skiable: 31.0 max_km_skiable: 31.0
url: "https://www.san-isidro.net" url: "https://www.san-isidro.net"
telegram_command: "/sanisidro"
webcams: webcams:
# Static snapshot URLs served by nieveleonsanisidro.com. # Static snapshot URLs served by nieveleonsanisidro.com.
# These are overwritten in-place on each camera refresh cycle (no timestamp). # These are overwritten in-place on each camera refresh cycle (no timestamp).
@@ -61,7 +59,6 @@ stations:
minimum_snow_depth: 30 minimum_snow_depth: 30
max_km_skiable: 8.6 max_km_skiable: 8.6
url: "https://www.fuentesdeinvierno.com" url: "https://www.fuentesdeinvierno.com"
telegram_command: "/fuentes"
webcams: webcams:
# fuentesdeinvierno.com serves snapshots under /tmp/ with a self-signed TLS # fuentesdeinvierno.com serves snapshots under /tmp/ with a self-signed TLS
# certificate. ssl_verify is set to false for these entries. # certificate. ssl_verify is set to false for these entries.