Last active
May 14, 2020 09:29
-
-
Save nickdos/42e7b9c2bbca9f06fa678925bb247e7a to your computer and use it in GitHub Desktop.
Shell scripts for biocache using JQ
This file contains 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
# find all DwC terms in index/fields | |
curl -s https://biocache-ws.ala.org.au/ws/index/fields | jq -r '.[] | select(.dwcTerm != null) | .dwcTerm ' | |
curl -s "https://biocache-ws.ala.org.au/ws/index/fields" | jq -r '.[] | select(.dwcTerm != null) | "\(.name)|\(.dwcTerm)" ' |
This file contains 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 bash | |
BIOCACHE_PREFIX="https://biocache-ws.ala.org.au/ws" | |
dwcCounts=("DwC term, SOLR field, count") | |
declare -A dwcFields | |
while IFS="|" read -r key value | |
do | |
dwcFields[$key]="$value" | |
done < <(curl -s --fail "${BIOCACHE_PREFIX}/index/fields" | jq -r '.[] | select(.dwcTerm != null and .indexed == true) | "\(.name)|\(.dwcTerm)" ') | |
for key in "${!dwcFields[@]}"; do | |
#echo "getting count for $key (${dwcFields[$key]})" | |
echo -n "." | |
count=$(curl -s --fail "${BIOCACHE_PREFIX}/occurrences/search?q=${key}:*&pageSize=0" | jq -r '.totalRecords') | |
dwcCounts+=("${dwcFields[$key]}, ${key}, ${count}") | |
done | |
echo -e "\n${#dwcCounts[@]} fields found\n\n" | |
printf '%s\n' "${dwcCounts[@]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment