from pathlib import Path
import urllib.request,concurrent.futures,hashlib,json
P=Path(__file__).resolve().parent; (P/'sources').mkdir(exist_ok=True)
parts=['RC0603JR-070RL','RC0603FR-07680RL','RC0603FR-07240KL']
def fetch(m):
 url='https://www.yageogroup.com/component-documentation/download/specsheet/'+m
 try:
  with urllib.request.urlopen(urllib.request.Request(url,headers={'User-Agent':'Mozilla/5.0'}),timeout=25) as r:data=r.read();ctype=r.headers.get('Content-Type','');final=r.url
  ext='.pdf' if data.startswith(b'%PDF') else '.html'; (P/'sources'/ (m+ext)).write_bytes(data)
  return {'MPN':m,'requested_url':url,'final_url':final,'bytes':len(data),'content_type':ctype,'sha256':hashlib.sha256(data).hexdigest(),'file':str(Path('sources')/(m+ext)),'fetch_status':'FETCHED_NOT_YET_PARAMETER_VERIFIED'}
 except Exception as e:return {'MPN':m,'requested_url':url,'fetch_status':'FAILED','error':str(e)}
with concurrent.futures.ThreadPoolExecutor(max_workers=7) as ex:rows=list(ex.map(fetch,parts))
(P/'source-fetch-delta-A88.json').write_text(json.dumps(rows,indent=2)+'\n'); print(json.dumps(rows))
