import csv, json, sys rows=list(csv.DictReader(open('cotejo/muestra_c.csv'))) d=json.load(open('cotejo/resp/avisos_api.json')) def s(v): if isinstance(v,dict): v=v.get('spa') or next(iter(v.values())) if isinstance(v,list): v=' | '.join(map(str,v[:8]))+(f' …(+{len(v)-8})' if len(v)>8 else '') return str(v) est=sys.argv[1] for r in rows: if r['est']!=est: continue n=d.get(r['aviso'],{}) print(f"== {r['est']} {r['unit'][-60:]} aviso {r['aviso']} anio {r['anio']}") print(f" P: exp={r['expediente']} | org={r['organo']} ({r['organo_nif']}) | obj={r['objeto'][:150]}") print(f" adj={r['adjudicatarios'][:120]} | nif={r['nifs'][:60]} | sin={float(r['imp_sin']):,.0f} con={float(r['imp_con']):,.0f} | fadj={r['fadj']} fform={r['fform']} | lote={r['lote_id'][-12:]}") print(f" T: {s(n.get('notice-type'))} pub={s(n.get('publication-date'))} exp={s(n.get('internal-identifier-proc',''))} | buyer={s(n.get('buyer-name'))} {s(n.get('buyer-identifier',''))}") print(f" title={s(n.get('title-proc',''))[:150]}") print(f" lots={s(n.get('title-lot',''))[:200]}") print(f" win={s(n.get('winner-name',''))[:200]} | wid={s(n.get('winner-identifier',''))[:100]} | val={s(n.get('tender-value',''))[:120]} tot={s(n.get('total-value',''))} concl={s(n.get('fecha-conclusion',''))[:60]}")