Skip to content
Open
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
68 changes: 68 additions & 0 deletions schema_validator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import json
import os
import sys
import xml.etree.ElementTree as ET

# Intentamos importar yaml para soporte extendido
try:
import yaml
HAS_YAML = True
except ImportError:
HAS_YAML = False

def validar_archivo(ruta):
if not os.path.exists(ruta):
print(f"Error: El archivo {ruta} no existe.")
sys.exit(1)

extension = os.path.splitext(ruta)[1].lower()

# Validacion de JSON
if extension == ".json":
try:
with open(ruta, "r", encoding="utf-8") as f:
json.load(f)
print("Confirmado: Archivo JSON valido.")
except json.JSONDecodeError as e:
print(f"Error en JSON: {e}")
sys.exit(1)

# Validacion de YAML
elif extension in [".yaml", ".yml"]:
if not HAS_YAML:
print("Error: Libreria PyYAML no instalada.")
sys.exit(1)
try:
with open(ruta, "r", encoding="utf-8") as f:
yaml.safe_load(f)
print("Confirmado: Archivo YAML valido.")
except Exception as e:
print(f"Error en YAML: {e}")
sys.exit(1)

# Validacion de XML (Especifico para el Bounty de ZIO)
elif extension == ".xml":
try:
tree = ET.parse(ruta)
# Verificacion basica de estructura
root = tree.getroot()
if root is None:
raise ValueError("El archivo XML esta vacio o no tiene nodo raiz.")
print(f"Confirmado: Archivo XML valido. Nodo raiz detectado: {root.tag}")
except ET.ParseError as e:
print(f"Error de sintaxis en XML: {e}")
sys.exit(1)
except Exception as e:
print(f"Error inesperado en XML: {e}")
sys.exit(1)

else:
print("Error: Formato no soportado. Use .json, .yaml o .xml")
sys.exit(1)

if __name__ == "__main__":
if len(sys.argv) < 2:
print("Uso: python validator.py <ruta_del_archivo>")
else:
validar_archivo(sys.argv[1])

1 change: 1 addition & 0 deletions vigilancia_pendiente.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"monto": "500", "wallet": "0xD9D9300003b141D825cB7f217162be01F5fe3871", "fecha": "Wed Mar 11 12:32:18 2026", "repo": "D:\\Blue_Dragon\\Kin\\projects\\yume\\yume_works\\trabajos\\zio-schema"}