Created
January 13, 2025 17:17
-
-
Save datadavev/fa61610bf7ef09be2267b0eb94102905 to your computer and use it in GitHub Desktop.
Quickie for retrieving a specific file from Zenodo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env zsh | |
usage() { | |
echo "List files for a Zotero DOI." | |
echo "Usage: zfile DOI [FNAME]" | |
echo " Show file contents on stdout if FNAME provided" | |
echo "example:" | |
echo " zfile 10.5281/zenodo.11400483 stac.json" | |
exit 1 | |
} | |
DOI="${1}" | |
FNAME="${2}" | |
if [ -z ${DOI} ]; then | |
usage | |
fi | |
LINK_URL=$(curl -s -H "Accept: application/json, */*;q=0.1" -L -o /dev/null -w "%header{link}" "https://doi.org/${DOI}" | sed -n "s/<\(.*\)>.*/\1/p") | |
>&2 echo "LINK URL: ${LINK_URL}" | |
if [ -z ${FNAME} ]; then | |
curl -s -H "Accept: application/json" ${LINK_URL} | jq '.files' | |
else | |
CONTENT_URL=$(curl -s -H "Accept: application/json" ${LINK_URL} | jq -r --arg fname "$FNAME" '.files[] | select(.key==$fname) | .links.self') | |
>&2 echo "CONTENT URL: ${CONTENT_URL}" | |
curl -s ${CONTENT_URL} | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment