"""Fetch only the six preselected images from the public dataset ZIP."""
import json
import zipfile
from pathlib import Path

from r16_archive_inspect import Remote

ROOT=Path(__file__).resolve().parent.parent
selection=json.loads((ROOT/'results/r16/selection.json').read_text())['selection']
destination=Path('/tmp/diatom-mask-images');destination.mkdir(exist_ok=True)
with zipfile.ZipFile(Remote()) as archive:
    for i,row in enumerate(selection,1):
        data=archive.read(row['zip_member'])  # zipfile verifies the member CRC.
        path=destination/f'{i:02d}.jpg';path.write_bytes(data)
        print(i,row['image']['file_name'],len(data),'bytes',flush=True)
