main
John Lauer Prepare five-board JLC SMT quote alternatives and native package; record upload success and unresolved sign-in/rotation… 6dfd908
"""Refresh quote-only supplier fields from saved live JLC evidence; no invented prices."""
import csv,json,pathlib
root=pathlib.Path(__file__).resolve().parents[1];q=root/'quotes/jlc-five-smt';p=q/'bom.csv';rows=list(csv.DictReader(p.open()));live={}
for folder in ['jlcpcb-flow/sourcing/live','jlcpcb-flow/alternatives/live']:
 for f in (root/folder).glob('C*.json'):
  try:
   d=json.loads(f.read_text());s=d.get('stdout');d=json.loads(s[s.index('{'):]) if s else d
   for c in d.get('components',[]):
    if c.get('source')=='live from JLCPCB':live[c['lcsc']]=(c,str(f.relative_to(root)))
  except (ValueError,KeyError,TypeError):pass
aliases={'R7':('ERJ-2RKF4701X','ERJ2RKF4701X','C400631'),'R8':('ERA-2AEB333X','ERA2AEB333X','C445615')};audit=[]
for r in rows:
 if r['fit']:continue
 if r['ref'] in aliases:
  old,mpn,c=aliases[r['ref']];assert r['mpn']==old;r['lcsc']=c
 c,e=live[r['lcsc']];r.update(source='JLCPCB',vendor_pn=r['lcsc'],stock_snapshot=str(c['stock']),stock_checked_on=c['stock_as_of'],unit_price_usd=str(c.get('unit_price_usd') or ''),product_url=c['jlcpcb_parts_url'])
 if r['ref'] in ['U1','U3']:r['value']=r['mpn']
 if r['ref']=='RSH1':r['value']='0.020 Ohm 0.25% Kelvin'
 r['note']='Quote-only; live JLC evidence '+e+'; unit price excludes assembly, attrition, freight and tax.'
 audit.append({'ref':r['ref'],'mpn':r['mpn'],'lcsc':r['lcsc'],'catalogMpn':c['mfr'],'stock':c['stock'],'evidence':e,'unitPrice':c.get('unit_price_usd')})
with p.open('w',newline='')as f:w=csv.DictWriter(f,list(rows[0]));w.writeheader();w.writerows(rows)
(q/'live-sourcing-audit.json').write_text(json.dumps(audit,indent=2))
(q/'exact-aliases.json').write_text(json.dumps(aliases,indent=2));print(len(audit),'SMT refs',len(set(x['lcsc']for x in audit)),'unique parts')