You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

zippleback.sh 820B

12345678910111213141516
  1. #!/bin/bash
  2. json="$(curl -m 5 -s https://barfandbel.ch/api/v2/quote.php)"
  3. if [ $? -gt 0 ]; then
  4. echo 'Failed to get quote from remote server!'
  5. exit 1
  6. else
  7. command -v jq > /dev/null
  8. if [ $? -eq 0 ]; then # Is the JQ binary present? https://stedolan.github.io/jq/tutorial/
  9. echo "$(echo $json | jq '.quote')" # I guess that's how you do that
  10. echo " - $(echo $json | jq '.character' | tr -d '"'), $(echo $json | jq '.source' | tr -d '"')" # tr removes all double quotes
  11. else #No jq? Then we'll use Python to parse the JSON
  12. echo "\"$(echo $json | python3 -c "import sys, json; print(json.load(sys.stdin)['quote'])")\""
  13. # I am mildy ashamed of this next line
  14. echo " - $(echo $json | python3 -c "import sys, json; j=json.load(sys.stdin); print(j['character'] + ', ' + j['source'])")"
  15. fi
  16. fi