from pathlib import Path import json,datetime R=Path.cwd();F=R/'docs/hel-892/animate2-loop-reference';rows=json.loads((F/'sources.json').read_bytes())['sources'] # Retain every original acquisition, select earliest known same repo/commit/path/SHA. prior=[] for p in (R/'docs/hel-892').glob('*/sources.json'): if p.parent==F:continue try:d=json.loads(p.read_bytes());old=d.get('sources',[])if isinstance(d,dict)else d except (ValueError,AttributeError):continue for e in old:prior.append((p,e)) changes=[] for e in rows: matches=[] for p,x in prior: if all(e.get(k)==x.get(k)for k in ['repo','commit','file','sha256']) and x.get('acquisition_time'): try:t=datetime.datetime.fromisoformat(x['acquisition_time'].replace('Z','+00:00'));assert t.utcoffset()is not None except (ValueError,AssertionError):continue matches.append(dict(record=str(p.relative_to(R)),acquisition_time=x['acquisition_time'])) if matches: current=e.get('acquisition_time');earliest=min([current]+[m['acquisition_time']for m in matches],key=lambda s:datetime.datetime.fromisoformat(s.replace('Z','+00:00'))) e['prior_acquisition_records']=matches;e['current_fetch_at']=current;e['acquisition_time']=earliest;e['acquisition_basis']='最早已知同repo/commit/path/SHA记录;不宣称全球首次';changes.append(dict(id=e['id'],file=e['file'],current_fetch_at=current,earliest_known=earliest,records=matches)) (F/'sources.json').write_text(json.dumps(dict(sources=rows),ensure_ascii=False,indent=2)+'\n');(F/'acquisition-history-final.json').write_text(json.dumps(changes,ensure_ascii=False,indent=2)+'\n') print('TOTAL',len(rows))