imrishabh18/fitness_watch

This circuit integrates an ESP-12E microcontroller with various sensors and peripherals, including a AO3400A MOSFET for switching loads, to enable wireless control and sensor data processing.

Version
1.0.12
License
unset
Stars
1

stock/check_inventory.py

import concurrent.futures, datetime, json, pathlib, subprocess, urllib.parse

root = pathlib.Path(__file__).parent
codes = json.loads((root/'required-codes.json').read_text())
def check(item):
    code, refs = item
    url='https://jlcsearch.tscircuit.com/api/search?'+urllib.parse.urlencode({'q':code,'full':'true','limit':100})
    raw=subprocess.check_output(['curl','-sS','--fail','--retry','2','--max-time','60',url])
    data=json.loads(raw)
    (root/(code+'.json')).write_bytes(raw)
    match=next((p for p in data.get('components',[]) if str(p.get('lcsc'))==code[1:]),None)
    if match is None and code == 'C25804':
        url='https://jlcsearch.tscircuit.com/resistors/list.json?resistance=10000&package=0603'
        raw=subprocess.check_output(['curl','-sS','--fail','--retry','2','--max-time','60',url])
        data=json.loads(raw)
        (root/(code+'-resistor-catalog.json')).write_bytes(raw)
        candidates=data if isinstance(data,list) else data.get('resistors',data.get('components',[]))
        match=next((p for p in candidates if str(p.get('lcsc'))==code[1:]),None)
    result={'code':code,'references':refs,'quantityPerWatch':len(refs),'requiredWatchQuantity':1,'queriedAtUTC':datetime.datetime.now(datetime.timezone.utc).isoformat(),'sourceUrl':url,'exactMatch':match is not None,'part':match}
    result['sufficientForOneWatch']=match is not None and match.get('stock',0)>=len(refs)
    return result

with concurrent.futures.ThreadPoolExecutor(max_workers=6) as pool:
    results=list(pool.map(check,codes.items()))
(root/'inventory.json').write_text(json.dumps(results,indent=2)+'\n')
for row in results:
    part=row['part'] or {}
    print(row['code'],part.get('mfr'), 'stock=',part.get('stock'), 'needed=',row['quantityPerWatch'],'OK' if row['sufficientForOneWatch'] else 'UNRESOLVED',flush=True)

if not all(row["sufficientForOneWatch"] for row in results):
    raise SystemExit("Stock check failed: inspect inventory.json")