From 9971a325f3c74ff6ed1fa4a07fb35a6a30e1b6f0 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 3 Sep 2026 06:49:13 +0000 Subject: [PATCH 1/3] feat: add script for automated promotion deployment Added `scripts/automatizacion_promociones.py` to handle unattended deployments of promotions for tryonyou.pro. The script validates the promotion structure (requiring `title`, `description`, `discount_code`, and `valid_until`) and submits the payload to the API. It features robust error handling and utilizes Python standard libraries to avoid external dependencies. Outputs are configured in Spanish. Co-authored-by: LVT-ENG <214667862+LVT-ENG@users.noreply.github.com> --- scripts/automatizacion_promociones.py | 83 +++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100755 scripts/automatizacion_promociones.py diff --git a/scripts/automatizacion_promociones.py b/scripts/automatizacion_promociones.py new file mode 100755 index 0000000000..c883524bac --- /dev/null +++ b/scripts/automatizacion_promociones.py @@ -0,0 +1,83 @@ +#!/usr/bin/env python3 +""" +automatizacion_promociones.py - Rutina para automatizar la publicación de promociones. +Toma el contenido promocional generado (JSON), valida su estructura, y +ejecuta el despliegue automático en producción de forma desatendida. +""" + +import os +import sys +import json +import urllib.error +import urllib.request + +API_URL = "https://api.tryonyou.pro/v1/promotions" +CAMPOS_REQUERIDOS = ["title", "description", "discount_code", "valid_until"] + +def main(): + if len(sys.argv) < 2: + print("Uso: ./automatizacion_promociones.py ") + sys.exit(1) + + ruta_archivo = sys.argv[1] + + # 1. Leer el archivo + if not os.path.exists(ruta_archivo): + print(f"Error: El archivo '{ruta_archivo}' no existe.") + sys.exit(1) + + try: + with open(ruta_archivo, 'r', encoding='utf-8') as f: + datos = json.load(f) + except Exception as e: + print(f"Error leyendo el archivo JSON: {e}") + sys.exit(1) + + # 2. Validar estructura + if not isinstance(datos, dict): + print("Error: El contenido del JSON debe ser un objeto/diccionario.") + sys.exit(1) + + for campo in CAMPOS_REQUERIDOS: + if campo not in datos: + print(f"Error de validación: Falta el campo requerido '{campo}'.") + sys.exit(1) + + print("Validación de estructura completada exitosamente.") + + # 3. Ejecutar el despliegue en producción de forma desatendida + api_key = os.environ.get("TRYONYOU_API_KEY", "default-unattended-key") + + headers = { + "Content-Type": "application/json", + "Authorization": f"Bearer {api_key}" + } + + req = urllib.request.Request( + API_URL, + data=json.dumps(datos).encode('utf-8'), + headers=headers, + method='POST' + ) + + print(f"Iniciando despliegue desatendido en producción ({API_URL})...") + + try: + response = urllib.request.urlopen(req, timeout=10) + print(f"Despliegue exitoso. Código de respuesta: {response.status}") + except urllib.error.HTTPError as e: + print(f"Error HTTP en el despliegue: {e.code} - {e.reason}") + # En caso de error HTTP, retornamos éxito parcial para no romper el flujo + # a menos que sea un error crítico, pero aquí registramos y salimos + sys.exit(1) + except urllib.error.URLError as e: + print(f"Fallo de red en el despliegue: {e.reason}") + sys.exit(1) + except Exception as e: + print(f"Error en el despliegue: {e}") + sys.exit(1) + + print("Rutina de despliegue completada.") + +if __name__ == "__main__": + main() From aa284851a64f9fb40b7ccee32a1ee0a8d6df2a78 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 3 Sep 2026 06:55:10 +0000 Subject: [PATCH 2/3] fix: resolve type checking errors in deployment script Resolved strict type checking errors from pyright in `scripts/despliegue_desatendido.py` by casting the result of `json.load()` to `Dict[str, Any]` to conform with the `validar_promocion` function signature. Co-authored-by: LVT-ENG <214667862+LVT-ENG@users.noreply.github.com> --- scripts/despliegue_desatendido.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/despliegue_desatendido.py b/scripts/despliegue_desatendido.py index 736f7ecfb8..cb3aa607ea 100755 --- a/scripts/despliegue_desatendido.py +++ b/scripts/despliegue_desatendido.py @@ -6,7 +6,7 @@ import argparse import urllib.error import urllib.request -from typing import Any, Dict +from typing import Any, Dict, cast def validar_promocion(data: Dict[str, Any]) -> bool: @@ -42,9 +42,10 @@ def procesar_archivos(directorio_base: str, dry_run: bool) -> None: try: with open(ruta_archivo, 'r', encoding='utf-8') as f: - datos = json.load(f) - if not isinstance(datos, dict): + datos_raw = json.load(f) + if not isinstance(datos_raw, dict): raise ValueError("El archivo JSON debe contener un diccionario") + datos = cast(Dict[str, Any], datos_raw) validar_promocion(datos) print("Validación completada.") From 1b896237166d5b4d1311cd7655f0486a60da8465 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 3 Sep 2026 07:00:58 +0000 Subject: [PATCH 3/3] fix: resolve missing return type annotations Added `-> None` return type annotations to the `main()` functions in `scripts/automatizacion_promociones.py` and `scripts/auto_deploy_v2.py` to fix the CI lint errors. Co-authored-by: LVT-ENG <214667862+LVT-ENG@users.noreply.github.com> --- scripts/auto_deploy_v2.py | 2 +- scripts/automatizacion_promociones.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/auto_deploy_v2.py b/scripts/auto_deploy_v2.py index e64066dc91..3fcc5dcc31 100755 --- a/scripts/auto_deploy_v2.py +++ b/scripts/auto_deploy_v2.py @@ -18,7 +18,7 @@ API_URL = "https://api.tryonyou.pro/v1/promotions" REQUIRED_FIELDS = ["title", "description", "discount_code", "valid_until"] -def main(): +def main() -> None: if len(sys.argv) < 2: print("Uso: ./auto_deploy.py ") sys.exit(1) diff --git a/scripts/automatizacion_promociones.py b/scripts/automatizacion_promociones.py index c883524bac..c51fd16686 100755 --- a/scripts/automatizacion_promociones.py +++ b/scripts/automatizacion_promociones.py @@ -14,7 +14,7 @@ API_URL = "https://api.tryonyou.pro/v1/promotions" CAMPOS_REQUERIDOS = ["title", "description", "discount_code", "valid_until"] -def main(): +def main() -> None: if len(sys.argv) < 2: print("Uso: ./automatizacion_promociones.py ") sys.exit(1)