"""python fetch_sources_378.py MANIFEST CACHE [--all]; checksum each pinned public artwork; never execute downloaded data."""
from pathlib import Path
from urllib.request import urlopen,Request
import sys,json,hashlib
p=Path(sys.argv[2]);p.mkdir(parents=True,exist_ok=True)
for name,e in json.loads(Path(sys.argv[1]).read_text()).items():
 if '--all' not in sys.argv and name not in ['countdown','opener13','opener14','other12','message14','status14','second14','originalTreeImage.jpg','originalTreeImageMirrored183x191NearestNeighbor.png']:continue
 f=p/e['local_filename'];b=f.read_bytes() if f.is_file() else urlopen(Request(e['url'],headers={'User-Agent':'Cicada-Research-Notebook'}),timeout=25).read()
 assert len(b)==e['bytes'] and hashlib.sha256(b).hexdigest()==e['sha256'],name
 if not f.exists():f.write_bytes(b)
