Files
Investidor-V2/outputs/investmoz-parques-mapa-20261016/extend-sources.py
T
nala cef6e201c7
tests / ci (push) Canceled after 0s
versao nrgocios 2
2026-10-16 20:11:05 +02:00

22 lines
2.0 KiB
Python

from pathlib import Path
import json,hashlib,zipfile,xml.etree.ElementTree as ET
out=Path(__file__).resolve().parent;inv=json.loads((out/'INVENTARIO-ACERVO.json').read_text('utf-8'));dest=out/'FONTES-LEVANTADAS.json';d=json.loads(dest.read_text('utf-8'))
names=['melhorar e transformar o Portal do Investidor atual.docx','upgrade do portal de investimentos v6 programacao.docx']
paths=[Path(x.get('path')or x.get('absolute_path')or Path(inv['corpus_inventory_reused']['root'])/x.get('relative_path',''))for x in inv['corpus_files']]
for p in paths:
if p.name not in names or str(p)in[x['path']for x in d['sources']]:continue
if not p.is_file():continue
with zipfile.ZipFile(p)as z:
ns={'w':'http://schemas.openxmlformats.org/wordprocessingml/2006/main'};tree=ET.fromstring(z.read('word/document.xml'))
paras=[''.join(n.text or ''for n in para.findall('.//w:t',ns))for para in tree.findall('.//w:p',ns)]
embeds=[{'entry':i.filename,'bytes':i.file_size,'CRC32':format(i.CRC,'08x')}for i in z.infolist()if not i.is_dir()and(i.filename.startswith('word/media/')or i.filename.startswith('word/embeddings/'))]
d['sources'].append({'path':str(p),'available':True,'bytes':p.stat().st_size,'sha256':hashlib.sha256(p.read_bytes()).hexdigest(),'suffix':'.docx','paragraphs':paras,'embedded':embeds,'selection':'Exact source named by existing park requirements; no master relationship inferred'})
if p.name==names[0]:
found=set()
for i,s in enumerate(paras):
if any(k in s.casefold()for k in ['ficha deve ser preenchida por parque','além dos campos comuns, cada parque','ficha operacional','infraestrutura comum','modelo de gestão','lotes internos']):
found.update(range(max(0,i-2),min(len(paras),i+18)))
print(json.dumps({'name':p.name,'sha256':hashlib.sha256(p.read_bytes()).hexdigest(),'selected_paragraphs':[{str(i+1):paras[i]}for i in sorted(found)]},ensure_ascii=True))
dest.write_text(json.dumps(d,ensure_ascii=False,indent=2)+'\n','utf-8')
print(json.dumps({'sources_total':len(d['sources'])}))