from pathlib import Path import csv,json P=Path(__file__).resolve().parent def rows(name): with (P/name).open() as f:return list(csv.DictReader(f)) def close(a,b):assert abs(float(a)-float(b))<0.0002,(a,b) out={} if (P/'world-production-reserves.csv').exists(): world=rows('world-production-reserves.csv');w=next(x for x in world if x['Geography']=='World total (rounded)') assert float(w['Mine 2025 estimate (kt)'])==23000 for r in rows('mine-ranking-2025.csv'):close(r['Share of rounded world total (%)'],float(r['Mine output estimate (kt)'])/23000*100) out['chile_share_percent']=5300/23000*100 out['forecast_gap_change_percentage_points']=30-25 elif (P/'global-fuel-estimates.csv').exists(): r=rows('global-fuel-estimates.csv');assert sum(float(x['2025 emissions estimate (Mt/year)']) for x in r)==124 for x in r:close(x['Share of published 124 Mt total (%)'],float(x['2025 emissions estimate (Mt/year)'])/124*100) s=rows('us-2015-segment-comparison.csv') for x in s:close(x['Difference in displayed central values (Tg/year)'],float(x['Study central estimate (Tg/year)'])-float(x['EPA inventory comparator (Tg/year)'])) out['historical_gap_Tg']=13-8.1;out['oil_gas_Mt']=45+36 else: q={x['Route or denominator']:x for x in rows('quarterly-oil-2025-2026.csv')} assert float(q['Strait of Hormuz']['3Q2026'])==9.1 for x in rows('quarterly-oil-changes.csv'): z=q[x['Route']];close(x['Same-quarter change (%)'],(float(z['3Q2026'])/float(z['3Q2025'])-1)*100) close(x['2Q2026 to 3Q2026 change (%)'],(float(z['3Q2026'])/float(z['2Q2026'])-1)*100) out['hormuz_year_on_year_percent']=(9.1/21.4-1)*100 print(json.dumps(out,indent=2))