Skip to content

Instantly share code, notes, and snippets.

@nickdos
Last active May 14, 2020 09:29
Show Gist options
  • Save nickdos/42e7b9c2bbca9f06fa678925bb247e7a to your computer and use it in GitHub Desktop.
Save nickdos/42e7b9c2bbca9f06fa678925bb247e7a to your computer and use it in GitHub Desktop.
Shell scripts for biocache using JQ
# 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)" '
#!/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