diff --git a/src/farmbot_yolo/download.py b/src/farmbot_yolo/download.py index fa732ab42316fd3914b69749259593835b913b12..cc13be776b6adb1c4f548c5423ad9e6307402e26 100644 --- a/src/farmbot_yolo/download.py +++ b/src/farmbot_yolo/download.py @@ -3,16 +3,14 @@ import argparse import os from pathlib import Path from typing import List +import json import requests from farmbot_yolo import creds +from farmbot_yolo import TMPDIR -# note: download only returns 100 at a time! -# note: we are currently ignoreing placeholders - -DEBUG_SKIP_DELETE_FILES = True IMG_FILE_SUFFIX = ".jpg" @@ -80,7 +78,19 @@ def download_images(directory: os.PathLike, delete_after=False) -> List[str]: with filepath.open(mode="wb") as fp: fp.write(img_req.content) - img_paths.append(filepath) + img_metadata_dict = { + "farmbot_metadata": { + "id": img_dict["id"], + "location": { + "x": img_dict["meta"]["x"], + "y": img_dict["meta"]["y"], + "z": img_dict["meta"]["z"], + }, + } + } + + with filepath.with_suffix(".json").open(mode="w") as fp: + json.dump(img_metadata_dict, fp) # post delete from cloud storage if delete_after: @@ -93,7 +103,10 @@ def download_images(directory: os.PathLike, delete_after=False) -> List[str]: if __name__ == "__main__": parser = argparse.ArgumentParser(description="Farmbot YOLO image downloader") parser.add_argument( - "download_dir", type=Path, help="Directory to download images too." + "download_dir", + type=Path, + help="Directory to download images too.", + default=TMPDIR, ) parser.add_argument("-d", "--delete", action="store_true")