mirror of
https://github.com/Dasemu/skipredictor.git
synced 2026-11-26 15:26:15 +00:00
refactor(bot): remove /all and station-specific commands
This commit is contained in:
1 parent
5e2a22340f
commit
32d8b07786
2 files changed
+5
-106
No files matched your search
+5
-103
@@ -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 <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:
|
||||
"""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 = (
|
||||
"<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 "
|
||||
"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"
|
||||
" - <b>Valgrande-Pajares</b>\n"
|
||||
" - <b>San Isidro</b>\n"
|
||||
" - <b>Fuentes de Invierno</b>\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 = (
|
||||
"<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"
|
||||
"/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))
|
||||
|
||||
Reference in new issue
Block a user