list_distritos_sorted.py
1.25 KB
import json
import sys
def list_sorted_districts(json_path):
try:
with open(json_path, 'r', encoding='utf-8') as f:
data = json.load(f)
features = data.get('features', [])
# Extraer y limpiar datos
dist_list = []
for feat in features:
p = feat.get('properties', {})
dist_list.append({
'dpto': p.get('cod_dpto', 'N/A'),
'dist': p.get('cod_dist', 0),
'name': p.get('nom_dist', 'N/A').strip()
})
# Ordenar por dpto y luego por dist (numérico)
dist_list.sort(key=lambda x: (x['dpto'], x['dist'] if isinstance(x['dist'], int) else 0))
print(f"{'DPTO':<5} | {'CODE':<5} | {'DISTRICT NAME'}")
print("-" * 50)
for d in dist_list:
print(f"{d['dpto']:<5} | {d['dist']:<5} | {d['name']}")
print("-" * 50)
print(f"TOTAL REGISTROS: {len(dist_list)}")
except Exception as e:
print(f"Error reading JSON: {e}", file=sys.stderr)
if __name__ == "__main__":
path = '/yvyape/proyectos/sigem-gis/snc_ly_dist.json'
list_sorted_districts(path)