"""E1b encendido · comprobación AÑADIDA Y POSTERIOR (no cambia el veredicto sellado de A4): los 10 lotes de A4 cuya ficha no da el número de ofertas por lote, contra la entrada ATOM original (CODICE) de los ZIP de la sindicación 643 (2023-2026), la de más reciente. Sin red. Lee /n (zips, :ro) y /w/interno/e1b; escribe /w/interno/e1b/25_atom_a4.json.""" import json, re, zipfile import xml.etree.ElementTree as ET from multiprocessing import Pool ZD = '/n/zips/licitaciones/' ZIPS = [ZD + f'licitacionesPerfilesContratanteCompleto3_{a}.zip' for a in (2023, 2024, 2025, 2026)] a = json.load(open('/w/interno/e1b/24_a3_a4.json')) ps = {p['par']: p for p in json.load(open('/w/interno/e1b/21_pares.json'))} obj = {} for x in a['A4']: if not x.get('legible_ofertas'): p = ps[x['par']] num = p['licitacion_id'].split('/')[-1]; lote = p['lote_u'].split('|')[-1] if '|' in p['lote_u'] else None obj[num] = {'par': x['par'], 'lote': lote, 'nuestro_ofertas': int(float(p['num_ofertas'])), 'adj': p['adj'], 'des': p['des']} RE_ID = re.compile(rb'https://contrataciondelestado\.es/sindicacion/licitacionesPerfilContratante/(\d+)') def buscar(args): zp, miembro = args out = [] with zipfile.ZipFile(zp) as z: data = z.read(miembro) for m in RE_ID.finditer(data): k = m.group(1).decode() if k not in obj: continue i0 = data.rfind(b'', m.end()) ent = data[i0:i1 + 8].decode('utf-8', 'replace') upd = re.search(r'([^<]+)', ent) out.append((k, upd.group(1) if upd else '', zp.split('_')[-1], ent)) return out tareas = [] for zp in ZIPS: with zipfile.ZipFile(zp) as z: tareas += [(zp, n) for n in z.namelist() if n.endswith('.atom')] print('ficheros', len(tareas), flush=True) mejor = {} with Pool(3) as pool: for res in pool.imap_unordered(buscar, tareas, chunksize=4): for k, upd, zn, ent in res: if k not in mejor or upd > mejor[k][0]: mejor[k] = (upd, zn, ent) json.dump({k: list(v) for k, v in mejor.items()}, open('/w/interno/e1b/25_entradas.json', 'w')) def tag(bloque, nombre): m = re.search(r'<(?:\w+:)?' + nombre + r'(?:\s[^>]*)?>([^<]*)', bloque) return m.group(1).strip() if m else None salida = [] for k, o in obj.items(): if k not in mejor: salida.append({**o, 'encontrado': False}); continue upd, zn, ent = mejor[k] res = [] for b in re.findall(r'<(?:\w+:)?TenderResult\b.*?', ent, flags=re.S): of = tag(b, 'ReceivedTenderQuantity') res.append({'lote': tag(b, 'ProcurementProjectLotID'), 'codigo': tag(b, 'ResultCode'), 'ofertas': int(float(of)) if of else None}) del_lote = [d for d in res if d['lote'] == o['lote']] ofs = sorted({d['ofertas'] for d in del_lote if d['ofertas'] is not None}) cods = sorted({d['codigo'] for d in del_lote if d['codigo']}) des_atom = bool(cods) and all(c in ('3', '6', '7') for c in cods) clase_ok = len(ofs) >= 1 and ((max(ofs) == 1) == (o['nuestro_ofertas'] == 1)) salida.append({**o, 'encontrado': True, 'updated': upd, 'zip': zn, 'ofertas_atom': ofs, 'codigos_atom': cods, 'igual_ofertas': ofs == [o['nuestro_ofertas']], 'clase_ok': clase_ok, 'resultado_ok': des_atom == (o['des'] == 'True' and o['adj'] != 'True')}) json.dump(salida, open('/w/interno/e1b/25_atom_a4.json', 'w'), indent=1) for s in salida: print(json.dumps({k: v for k, v in s.items() if k != 'ent'}))