Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/auto_deploy_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def validar_promocion(data: Dict[str, Any]) -> None:
if campo not in data:
raise ValueError(f"Falta el campo requerido: {campo}")

def main():
def main() -> None:
if len(sys.argv) < 2:
print("Uso: python3 auto_deploy_v2.py <ruta_al_archivo_json>")
sys.exit(1)
Expand Down
15 changes: 11 additions & 4 deletions scripts/automatizacion_despliegue.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""

import os
import re
import sys
import json
import time
Expand Down Expand Up @@ -40,15 +41,21 @@ def process_file(filepath: str, dry_run: bool) -> bool:
with open(filepath, "r", encoding="utf-8") as f:
contenido_archivo = f.read()

match = re.search(r"```(?:json)?\s*(\{.*?\})\s*```", contenido_archivo, re.DOTALL)
if match:
contenido_limpio = match.group(1).strip()
else:
contenido_limpio = contenido_archivo.strip()

try:
datos_cargados = json.loads(contenido_archivo)
datos_cargados = json.loads(contenido_limpio)
except json.JSONDecodeError as e:
# Fallback en caso de que el LLM incluya texto extra
if e.pos > 0:
try:
datos_cargados = json.loads(contenido_archivo[:e.pos])
except json.JSONDecodeError:
raise ValueError(f"Error parseando JSON incluso con el texto extra cortado.")
datos_cargados = json.loads(contenido_limpio[:e.pos])
except json.JSONDecodeError as err:
raise ValueError(f"Error parseando JSON incluso con el texto extra cortado.") from err
else:
raise

Expand Down
Loading