import os import csv import json BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '../estratti')) output = {} for root, _, files in os.walk(BASE_DIR): for fname in files: if fname.lower().endswith('.csv'): fpath = os.path.join(root, fname) relpath = os.path.relpath(fpath, BASE_DIR) try: with open(fpath, encoding='utf-8') as f: reader = csv.reader(f) header = next(reader) row_count = sum(1 for _ in reader) output[relpath] = { "header": header, "rows": row_count } print(f"[OK] {relpath}: {len(header)} colonne, {row_count} righe") except Exception as e: output[relpath] = {"error": str(e)} print(f"[ERRORE] {relpath}: {e}") with open("panoramica_estratti.json", "w", encoding="utf-8") as out: json.dump(output, out, indent=2, ensure_ascii=False) print("\nPanoramica salvata in 'panoramica_estratti.json'. Inviami questo file per analisi delle relazioni!")