# main.py import json from pathlib import Path from utils.texttools import split_display_sections from models.hpe5130 import SwitchHPE5130 def read_file_with_fallback(path: Path) -> str: try: return path.read_text(encoding="utf-8") except UnicodeDecodeError: print("[warn] UTF-8 échoué, tentative avec cp1252...") return path.read_text(encoding="cp1252") def main(): log_path = Path("data/example-a.log") if not log_path.exists(): print(f"Fichier non trouvé : {log_path}") return content = read_file_with_fallback(log_path) sections = split_display_sections(content) switch = SwitchHPE5130() for section in sections: switch.parse_block(section["section"], section["content"]) output_path = Path("data/switch_parsed.json") with open(output_path, "w", encoding="utf-8") as f: json.dump(switch.to_dict(), f, indent=2, ensure_ascii=False) print(f"Switch exporté dans {output_path}") if __name__ == "__main__": main()