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

22 lines
1.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from pathlib import Path
import hashlib,json,xml.etree.ElementTree as ET,zipfile
out=Path(__file__).resolve().parent;sha=lambda p:hashlib.sha256(p.read_bytes()).hexdigest()
m=out/'MANIFESTO-FONTES.json';d=json.loads(m.read_text('utf-8'));private=[]
specs=[('23b033e6-9ee3-4a6c-a41b-688fe7f09795','5dbf82c2d8ba2c9056b838c4565cb0db9de28da4173075bfdc12b233b3c43fe9',1000,1060),
('d53670c4-f46a-4d49-b188-770b86bdda19','c71ec7adb5af079fc5c93536107fe30ffc0906700b5ee5eef6bd2cca1665dfde',15,130)]
for folder,h,start,end in specs:
p=Path('C:/Users/macbook/.codex/attachments')/folder/'Pasted text.txt';assert sha(p)==h
lines=p.read_text('utf-8-sig').splitlines()
item={'name':p.name,'sha256':h,'bytes':p.stat().st_size,'available':True,'origin':'user-supplied project instruction already referenced in existing matrix',
'citation':f'lines {start}–{end}','embedded_resources':[]}
d['sources'].append(item);private.append({'source':item,'excerpts':[{'line':i+1,'text':lines[i]}for i in range(start-1,min(end,len(lines)))]})
paths=json.loads((out/'FONTES-CAMINHOS-PRIVADOS.json').read_text('utf-8'))
p=Path(next(x['path']for x in paths if x['sha256'].startswith('e1169a77')))
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)]
private.append({'name':p.name,'sha256':sha(p),'excerpts':[{'paragraph':i+1,'text':paras[i]}for i in range(1438,1445)]})
(out/'ORIGENS-EXCERTOS-PRIVADOS.json').write_text(json.dumps(private,ensure_ascii=False,indent=2)+'\n','utf-8')
m.write_text(json.dumps(d,ensure_ascii=False,indent=2)+'\n','utf-8')
print(json.dumps(private,ensure_ascii=True))