diff --git a/Dockerfile b/Dockerfile index e5f2441..0f0a6ba 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,6 +6,7 @@ RUN set -e \ # && apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends --yes \ make=4.3-4.1 \ + curl=7.74.0-1.3+deb11u10 \ # # clean-up # diff --git a/Makefile b/Makefile index 1f8da33..5fd0969 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,7 @@ VERBOSE:= ZIP:=zip ZIPOPTIONS:=-u -r ZIPIGNORES:=-x \*.DS_Store\* -x \*.gitkeep\* -x data/csv/\* +ZENODO_DOWNLOAD=$(PYTHON) bin/zenodo-download.py DOWNLOAD:=$(PYTHON) bin/download.py $(VERBOSE) BOATOCSV:=$(PYTHON) bin/boa-to-csv.py @@ -74,6 +75,16 @@ zenodo: $(PYTHON) bin/zenodo.py +########################## +# downloading from Zenodo +# +get-data: + $(ZENODO_DOWNLOAD) data.zip + +get-cache: + $(ZENODO_DOWNLOAD) data-cache.zip + + ################ # clean targets # diff --git a/bin/zenodo-download.py b/bin/zenodo-download.py new file mode 100755 index 0000000..8d8fa8a --- /dev/null +++ b/bin/zenodo-download.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python3 +# coding: utf-8 + +import json +import os +from pathlib import Path +import subprocess +import sys + + +JSON_FILENAME = '.zenodo.json' + + +def get_deposition_id(): + if 'prereserve_doi' in json_data: + if isinstance(json_data['prereserve_doi'], dict) and 'recid' in json_data['prereserve_doi']: + return json_data['prereserve_doi']['recid'] + return None + + +if __name__ == '__main__': + if len(sys.argv) != 2: + print('usage: zenodo-download.py ') + sys.exit(-1) + filename = sys.argv[1] + + # make sure we have a JSON metadata file + if not Path(JSON_FILENAME).exists(): + print('no Zenodo JSON metadata file found') + sys.exit(-1) + + with open(JSON_FILENAME) as f: + json_data = json.load(f) + + # ensure there is a deposition + deposition_id = get_deposition_id() + if not deposition_id: + print('unable to find a Zenodo deposition') + sys.exit(-1) + + # download the file + print('downloading file...') + + try: + os.remove(filename) + except: + pass + + url = f'https://zenodo.org/records/{deposition_id}/files/{filename}?download=1' + proc = subprocess.run(['curl', '-L', '--fail-with-body', '-o', filename, url]) + + if proc.returncode == 0: + print('download complete') + else: + print(f'error downloading file "{filename}" from "{url}"') + try: + os.remove(filename) + except: + pass + sys.exit(-1)