From 32d8b0778634bfa87ccf7dc0424e9771ae1d818f Mon Sep 17 00:00:00 2001 From: Dasemu Date: Tue, 17 Mar 2026 17:46:42 +0100 Subject: [PATCH] refactor(bot): remove /all and station-specific commands --- bot/telegram_bot.py | 108 ++----------------------------------------- config/stations.yaml | 3 -- 2 files changed, 5 insertions(+), 106 deletions(-) diff --git a/bot/telegram_bot.py b/bot/telegram_bot.py index ba39a2c..4c45371 100644 --- a/bot/telegram_bot.py +++ b/bot/telegram_bot.py @@ -1,14 +1,9 @@ """ Telegram bot for the ski predictor system. -Serves published predictions for three ski stations in northern Spain: - - Valgrande-Pajares (/pajares) - - San Isidro (/sanisidro) - - 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. +Reads forecasts from the ``current_forecasts`` / ``past_forecasts`` tables in +SQLite and serves multi-station horizon commands for three ski stations in +northern Spain. Usage: 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) -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 {station_name} en este " - f"momento.\n\n" - f"El pipeline de datos se ejecuta diariamente. " - f"Inténtalo de nuevo más tarde." - ) - - def _unavailable_message() -> str: """Return a message when published predictions cannot be loaded at all.""" return ( @@ -405,12 +390,8 @@ async def cmd_start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: text = ( "¡Bienvenido al bot de predicción de estaciones de esquí!\n\n" "Este bot te informa sobre la predicción vigente para tres " - "estaciones de esquí del norte de España.\n" - "Hasta las 10:00 muestra preferentemente la predicción del mismo " - "día; después, la del día siguiente.\n\n" - " - Valgrande-Pajares\n" - " - San Isidro\n" - " - Fuentes de Invierno\n\n" + "estaciones de esquí del norte de España: " + "Valgrande-Pajares, San Isidro y Fuentes de Invierno.\n\n" "Las predicciones combinan reglas operacionales y modelos de " "aprendizaje automático basados en datos meteorológicos.\n\n" "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.""" text = ( "Comandos disponibles:\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" "/manana — Predicción de mañana para las tres estaciones\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) -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( update: Update, 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: """Handle the /hoy command — three-station prediction for today.""" 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("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("manana", cmd_manana)) app.add_handler(CommandHandler("tresdias", cmd_tresdias)) diff --git a/config/stations.yaml b/config/stations.yaml index 9fe079d..888c013 100644 --- a/config/stations.yaml +++ b/config/stations.yaml @@ -8,7 +8,6 @@ stations: minimum_snow_depth: 30 # cm max_km_skiable: 22.0 url: "https://www.valgrande-pajares.com" - telegram_command: "/pajares" webcams: # infonieve.es embeds a timestamp in the filename for Pajares. # The collector resolves the current URL by scraping the page at runtime. @@ -33,7 +32,6 @@ stations: minimum_snow_depth: 30 max_km_skiable: 31.0 url: "https://www.san-isidro.net" - telegram_command: "/sanisidro" webcams: # Static snapshot URLs served by nieveleonsanisidro.com. # These are overwritten in-place on each camera refresh cycle (no timestamp). @@ -61,7 +59,6 @@ stations: minimum_snow_depth: 30 max_km_skiable: 8.6 url: "https://www.fuentesdeinvierno.com" - telegram_command: "/fuentes" webcams: # fuentesdeinvierno.com serves snapshots under /tmp/ with a self-signed TLS # certificate. ssl_verify is set to false for these entries.