From 21409767528bed946422a066613f82a97cf5d7b9 Mon Sep 17 00:00:00 2001 From: Tuomas Siipola Date: Thu, 2 Nov 2023 16:13:35 +0200 Subject: [PATCH] Fix `fetch` with multiple files of same name --- src/data_processing/subcmds/fetch_data_to_dev.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/data_processing/subcmds/fetch_data_to_dev.py b/src/data_processing/subcmds/fetch_data_to_dev.py index 2b5fd7f0..b662bc81 100644 --- a/src/data_processing/subcmds/fetch_data_to_dev.py +++ b/src/data_processing/subcmds/fetch_data_to_dev.py @@ -105,7 +105,15 @@ def _process_row(row: dict, args: argparse.Namespace): def _download_file(row: dict) -> Path: res = requests.get(row["downloadUrl"]) res.raise_for_status() - filename = DOWNLOAD_DIR / row["filename"] + if "instrumentPid" in row: + subdir = row["instrument"]["id"] + "-" + row["instrumentPid"].split(".")[-1][:8] + elif "model" in row: + subdir = "model-" + row["model"]["id"] + else: + raise ValueError("Row does not contain instrument or model.") + outdir = DOWNLOAD_DIR / subdir + outdir.mkdir(exist_ok=True, parents=True) + filename = outdir / row["filename"] filename.write_bytes(res.content) return filename