mirror of
https://github.com/Dasemu/skipredictor.git
synced 2026-11-26 15:26:15 +00:00
feat(bot): translate all telegram bot messages to spanish
This commit is contained in:
1 parent
1bc1e58781
commit
b690e82f98
3 files changed
+48
-48
No files matched your search
+28
-28
@@ -75,16 +75,16 @@ def load_predictions() -> dict | None:
|
||||
or cannot be decoded.
|
||||
"""
|
||||
if not PREDICTIONS_FILE.exists():
|
||||
logger.warning("Predictions file not found: %s", PREDICTIONS_FILE)
|
||||
logger.warning("Archivo de predicciones no encontrado: %s", PREDICTIONS_FILE)
|
||||
return None
|
||||
|
||||
try:
|
||||
with PREDICTIONS_FILE.open(encoding="utf-8") as fh:
|
||||
data = json.load(fh)
|
||||
logger.info("Predictions loaded from %s", PREDICTIONS_FILE)
|
||||
logger.info("Predicciones cargadas desde %s", PREDICTIONS_FILE)
|
||||
return data
|
||||
except json.JSONDecodeError as exc:
|
||||
logger.error("Failed to decode predictions file: %s", exc)
|
||||
logger.error("Error al decodificar el archivo de predicciones: %s", exc)
|
||||
return None
|
||||
|
||||
|
||||
@@ -129,8 +129,8 @@ def _extract_station_predictions(payload: dict[str, Any]) -> dict[str, dict[str,
|
||||
def _message_title(station_name: str, prediction_date: str | None) -> str:
|
||||
"""Return the station header including the prediction date when known."""
|
||||
if prediction_date:
|
||||
return f"{station_name} - Prediccion para {prediction_date}"
|
||||
return f"{station_name} - Prediccion para manana"
|
||||
return f"{station_name} - Predicción para {prediction_date}"
|
||||
return f"{station_name} - Predicción para mañana"
|
||||
|
||||
|
||||
def format_station_prediction(
|
||||
@@ -176,7 +176,7 @@ def format_station_prediction(
|
||||
source = str(
|
||||
prediction.get(
|
||||
"prediction_source",
|
||||
prediction.get("source", "prediccion hibrida (reglas + ML)"),
|
||||
prediction.get("source", "predicción híbrida (reglas + ML)"),
|
||||
)
|
||||
)
|
||||
|
||||
@@ -200,12 +200,12 @@ def format_station_prediction(
|
||||
|
||||
weather_lines: list[str] = []
|
||||
if temp_min is not None and temp_max is not None:
|
||||
weather_lines.append(f"Temperatura: {temp_min:.0f}C / {temp_max:.0f}C")
|
||||
weather_lines.append(f"Temperatura: {temp_min:.0f}ºC / {temp_max:.0f}ºC")
|
||||
elif temp_max is not None:
|
||||
weather_lines.append(f"Temperatura maxima: {temp_max:.0f}C")
|
||||
weather_lines.append(f"Temperatura máxima: {temp_max:.0f}ºC")
|
||||
|
||||
if snowfall is not None:
|
||||
weather_lines.append(f"Nieve: {snowfall:.0f}cm nuevos")
|
||||
weather_lines.append(f"Nieve: {snowfall:.0f} cm nuevos")
|
||||
|
||||
if wind_speed is not None and wind_gust is not None:
|
||||
weather_lines.append(
|
||||
@@ -239,10 +239,10 @@ def format_station_prediction(
|
||||
def _no_prediction_message(station_name: str) -> str:
|
||||
"""Return a friendly error message when prediction data is unavailable."""
|
||||
return (
|
||||
f"Lo siento, no hay prediccion disponible para <b>{station_name}</b> en este "
|
||||
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"Intentalo de nuevo mas tarde.</i>"
|
||||
f"Inténtalo de nuevo más tarde.</i>"
|
||||
)
|
||||
|
||||
|
||||
@@ -250,8 +250,8 @@ def _unavailable_message() -> str:
|
||||
"""Return a message when the predictions file cannot be loaded at all."""
|
||||
return (
|
||||
"No se han podido cargar las predicciones.\n\n"
|
||||
"<i>Asegurate de que el pipeline diario se ha ejecutado correctamente. "
|
||||
"Intentalo de nuevo mas tarde.</i>"
|
||||
"<i>Asegúrate de que el pipeline diario se ha ejecutado correctamente. "
|
||||
"Inténtalo de nuevo más tarde.</i>"
|
||||
)
|
||||
|
||||
|
||||
@@ -263,14 +263,14 @@ def _unavailable_message() -> str:
|
||||
async def cmd_start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
"""Handle the /start command with a welcome message."""
|
||||
text = (
|
||||
"<b>Bienvenido al bot de prediccion de estaciones de esqui!</b>\n\n"
|
||||
"Este bot te informa sobre las condiciones previstas para el dia "
|
||||
"siguiente en tres estaciones de esqui del norte de Espana:\n\n"
|
||||
"<b>¡Bienvenido al bot de predicción de estaciones de esquí!</b>\n\n"
|
||||
"Este bot te informa sobre las condiciones previstas para el día "
|
||||
"siguiente en tres estaciones de esquí del norte de España:\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 "
|
||||
"aprendizaje automatico basados en datos meteorologicos.\n\n"
|
||||
"aprendizaje automático basados en datos meteorológicos.\n\n"
|
||||
"Escribe /help para ver los comandos disponibles."
|
||||
)
|
||||
await update.message.reply_text(text, parse_mode=ParseMode.HTML)
|
||||
@@ -280,9 +280,9 @@ 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 — Prediccion para Valgrande-Pajares\n"
|
||||
"/sanisidro — Prediccion para San Isidro\n"
|
||||
"/fuentes — Prediccion para Fuentes de Invierno\n"
|
||||
"/pajares — Predicción para Valgrande-Pajares\n"
|
||||
"/sanisidro — Predicción para San Isidro\n"
|
||||
"/fuentes — Predicción para Fuentes de Invierno\n"
|
||||
"/all — Predicciones para las tres estaciones\n"
|
||||
"/help — Mostrar esta ayuda\n"
|
||||
)
|
||||
@@ -310,7 +310,7 @@ async def _send_station(
|
||||
station_predictions = _extract_station_predictions(predictions)
|
||||
station_pred = station_predictions.get(station_key)
|
||||
if not station_pred:
|
||||
logger.warning("No prediction entry for station '%s'", station_key)
|
||||
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
|
||||
@@ -322,7 +322,7 @@ async def _send_station(
|
||||
predictions.get("prediction_date"),
|
||||
)
|
||||
except Exception as exc: # noqa: BLE001
|
||||
logger.exception("Error formatting prediction for '%s': %s", station_key, exc)
|
||||
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)
|
||||
@@ -330,25 +330,25 @@ async def _send_station(
|
||||
|
||||
async def cmd_pajares(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
"""Handle the /pajares command — prediction for Valgrande-Pajares."""
|
||||
logger.info("User %s requested /pajares", update.effective_user.id)
|
||||
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("User %s requested /sanisidro", update.effective_user.id)
|
||||
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("User %s requested /fuentes", update.effective_user.id)
|
||||
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("User %s requested /all", update.effective_user.id)
|
||||
logger.info("El usuario %s solicitó /all", update.effective_user.id)
|
||||
for station_key in ("pajares", "sanisidro", "fuentes"):
|
||||
await _send_station(update, station_key)
|
||||
|
||||
@@ -368,11 +368,11 @@ def main() -> None:
|
||||
token = os.environ.get("TELEGRAM_BOT_TOKEN")
|
||||
if not token:
|
||||
raise EnvironmentError(
|
||||
"La variable de entorno TELEGRAM_BOT_TOKEN no esta definida. "
|
||||
"La variable de entorno TELEGRAM_BOT_TOKEN no está definida. "
|
||||
"Configura el token del bot antes de iniciar."
|
||||
)
|
||||
|
||||
logger.info("Iniciando bot de prediccion de esqui...")
|
||||
logger.info("Iniciando bot de predicción de esquí...")
|
||||
|
||||
app = Application.builder().token(token).build()
|
||||
|
||||
|
||||
Reference in new issue
Block a user