From 47b8aedcebb7d686d5ef0e35b90cb55c05f0c100 Mon Sep 17 00:00:00 2001
From: Anton Tetov <anton@tetov.se>
Date: Mon, 13 Jun 2022 22:47:41 +0200
Subject: [PATCH] download metadata together with images

---
 src/farmbot_yolo/download.py | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/src/farmbot_yolo/download.py b/src/farmbot_yolo/download.py
index fa732ab..cc13be7 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")
 
-- 
GitLab