Files
Investidor-V2/outputs/investmoz-referencias-economicas-mapa-20261016/inventory.py
T
nala 2d23157e40
tests / ci (push) Canceled after 0s
versao nrgocios
2026-10-16 13:06:58 +02:00

31 lines
2.5 KiB
Python

from pathlib import Path
import json,hashlib,zipfile,csv,unicodedata,datetime
root=Path(__file__).resolve().parents[2];out=Path(__file__).resolve().parent
corpus=Path('C:/Mac/Home/Documents/TEMPO/Portal Tempo');attachments=Path('C:/Users/macbook/.codex/attachments')
assert not (out/'INVENTARIO-ACERVO.json').exists()
norm=lambda s:unicodedata.normalize('NFKD',s.casefold()).encode('ascii','ignore').decode()
records=[];embedded=[]
for label,folder in [('acervo_tempo',corpus),('anexos_instrucoes',attachments)]:
if not folder.is_dir():continue
for p in sorted(folder.rglob('*')):
if not p.is_file():continue
records.append({'root':label,'path':str(p),'relative_path':str(p.relative_to(folder)),'bytes':p.stat().st_size,'suffix':p.suffix.lower()})
if p.suffix.lower()=='.docx' and not p.name.startswith('~$'):
try:
with zipfile.ZipFile(p) as z:
for i in z.infolist():
if not i.is_dir() and (i.filename.startswith('word/media/') or i.filename.startswith('word/embeddings/')):
embedded.append({'container':str(p),'entry':i.filename,'bytes':i.file_size,'CRC32':format(i.CRC,'08x')})
except zipfile.BadZipFile:embedded.append({'container':str(p),'error':'Container not readable as DOCX; preserved in inventory'})
history=[]
for n,delimiter in [('docs/investmoz/v2/auditoria-portal/inventario-fontes.csv',','),('docs/investmoz/document-corpus-inventory-2026-10-06.csv',';')]:
p=root/n
with p.open(encoding='utf-8-sig',newline='') as f:rows=list(csv.DictReader(f,delimiter=delimiter))
history.append({'path':n,'sha256':hashlib.sha256(p.read_bytes()).hexdigest(),'records':len(rows)})
proof={'date':'2026-10-16','scope':'Inventory before selecting economic references; originals, instruction attachments and embedded resources retained irrespective of consumer relevance','roots':[str(corpus),str(attachments)],'files':records,'embedded':embedded,'historical_inventories_reused':history,'publications':0,'active_changes':0}
(out/'INVENTARIO-ACERVO.json').write_text(json.dumps(proof,ensure_ascii=False,indent=2)+'\n','utf-8')
keys=['cae','classific','economic','economica','cadeia','cluster','agroneg','agro-industr','parque','industrial','sectores','setores','oportunidad','corredor']
selected=[r for r in records if r['root']=='acervo_tempo' and any(k in norm(r['relative_path']) for k in keys)]
(out/'CANDIDATOS-POR-NOME.json').write_text(json.dumps(selected,ensure_ascii=False,indent=2)+'\n','utf-8')
print(json.dumps({'files':len(records),'embedded':len(embedded),'history':history,'candidate_names':[r['relative_path'] for r in selected]},ensure_ascii=True))