Difference between revisions of "User:Andreas Plank/Useful Scripts (Linux)"

From CETAF Identifiers Wiki
Jump to: navigation, search
(Created page with "== Get IDs of api.ror.org by Query == <syntaxhighlight lang="bash" style="font-size:smaller;"> # ############################################## # dependency: curl # dependenc...")
 
m (?comments)
Line 17: Line 17:
 
if [[ "$number_of_pages" =~ ^[0-9]+$ ]]; then
 
if [[ "$number_of_pages" =~ ^[0-9]+$ ]]; then
 
   for ((p=1; p<=$number_of_pages; p++)); do
 
   for ((p=1; p<=$number_of_pages; p++)); do
   echo "# page $p => ror.org_page-$p.json"
+
   echo "# get content of page $p => ror.org_page-$p.json"
 
     contents=$(curl --silent --get https://api.ror.org/organizations --data-urlencode "query=$query_string" --data-urlencode "page=$p" )
 
     contents=$(curl --silent --get https://api.ror.org/organizations --data-urlencode "query=$query_string" --data-urlencode "page=$p" )
 
     echo "$contents" > "ror.org_page-$p.json"
 
     echo "$contents" > "ror.org_page-$p.json"
 
   done
 
   done
 
   jq --slurp '{ items: map(.items[]) }' ror.org_page-*.json > ror.org_page-all.json
 
   jq --slurp '{ items: map(.items[]) }' ror.org_page-*.json > ror.org_page-all.json
 +
  # parse multiple files and concatenate the { items : [] }
 +
 
   jq '.items|=sort_by(.name)|.items [] | (.id + "::" + .name)' ror.org_page-all.json
 
   jq '.items|=sort_by(.name)|.items [] | (.id + "::" + .name)' ror.org_page-all.json
 +
  # find in { items : [ {id : … , name : …}] } and concatenate them via "::"
 
else
 
else
 
   echo "Something wrong: \$number_of_pages is not an integer ()"
 
   echo "Something wrong: \$number_of_pages is not an integer ()"

Revision as of 15:14, 25 June 2020

Get IDs of api.ror.org by Query

# ##############################################
# dependency: curl
# dependency: jq (JSON tool)
# dependency: awk
# get from exact query
curl -G https://api.ror.org/organizations --data-urlencode 'query="Botanischer Garten und Botanisches Museum Berlin"' | jq . > bgbm.org.json
jq '.items|=sort_by(.name)|.items [] | (.id + "::" + .name)' bgbm.org.json 
# "https://ror.org/00bv4cx53::Botanischer Garten und Botanisches Museum Berlin"

# get from multiple result pages
query_string="Botanisch Garten garden botanical"
number_of_results=`curl --silent --get https://api.ror.org/organizations --data-urlencode "query=$query_string" | jq ".number_of_results"`
number_of_pages=`echo "scale=0; ${number_of_results}/20 + 0.5" | bc -l | awk '{printf("%d\n",$1 + 0.5)}'`
if [[ "$number_of_pages" =~ ^[0-9]+$ ]]; then
  for ((p=1; p<=$number_of_pages; p++)); do
  echo "# get content of page $p => ror.org_page-$p.json"
    contents=$(curl --silent --get https://api.ror.org/organizations --data-urlencode "query=$query_string" --data-urlencode "page=$p" )
    echo "$contents" > "ror.org_page-$p.json"
  done
  jq --slurp '{ items: map(.items[]) }' ror.org_page-*.json > ror.org_page-all.json
  # parse multiple files and concatenate the { items : [] }

  jq '.items|=sort_by(.name)|.items [] | (.id + "::" + .name)' ror.org_page-all.json
  # find in { items : [ {id : … , name : …}] } and concatenate them via "::"
else
  echo "Something wrong: \$number_of_pages is not an integer ()"
fi
# "https://ror.org/02z4j5834::American Public Gardens Association"
# "https://ror.org/007x2j456::Batumi Botanical Garden"
# …
# "https://ror.org/00bv4cx53::Botanischer Garten und Botanisches Museum Berlin"
# …
# "https://ror.org/01h1jbk91::Meise Botanic Garden"
# …
# "https://ror.org/0349vqz63::Royal Botanic Garden Edinburgh"
# …
# "https://ror.org/03pjnvf85::Zürich Zoological Garden"
# ##############################################