Skip to content

Instantly share code, notes, and snippets.

@yoplait
Last active June 26, 2022 18:39
Show Gist options
  • Save yoplait/becbefa04958e2e1dd1ac919b6c53733 to your computer and use it in GitHub Desktop.
Save yoplait/becbefa04958e2e1dd1ac919b6c53733 to your computer and use it in GitHub Desktop.
Exercise 2: Find all ships that have a hyperdrive rating >= 1.0
#!/usr/bin/env bash
##########################################################################################
# Exercise 2: Find all ships that have a hyperdrive rating >= 1.0
clear
URL='https://swapi.dev/api'
PAGE=1
echo ""
echo "Exercise 2: Find all ships that have a hyperdrive rating >= 1.0"
echo ""
while true
do
response=$( curl -sL -H 'Accept: application/json' ${URL}/starships?page=${PAGE} )
if [[ ${response} =~ .*detail.*Not.* ]]; then
break
fi
echo $response | jq '.results[] | select(.hyperdrive_rating>="1.0").name'
PAGE=$((PAGE + 1))
done
echo ""
echo "API Pages:" $((PAGE - 1))
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment