From 8f2e371464a9af99d8878e39890c085abcceeaa6 Mon Sep 17 00:00:00 2001 From: ars Date: Thu, 23 Jul 2020 18:08:40 +0100 Subject: Add appkey to API requests --- livetimes.sh | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/livetimes.sh b/livetimes.sh index c7ce414..4bcfa27 100755 --- a/livetimes.sh +++ b/livetimes.sh @@ -9,16 +9,15 @@ _jq() { } _liveresult() { - stops=$(curl --fail --silent https://admin.libertybus.je/api/v1/stops/"${stop}") + stops=$(curl --fail --silent -H "App-Key: A4E247A48AAF12BF2E97D9F346E56" https://admin.libertybus.je/api/v1/stops/"${stop}") stopname=$(echo $stops | jq '.[].name') - livetimes=$(curl --fail --silent https://admin.libertybus.je/api/v1/soj/stop_updates/${stop}) + livetimes=$(curl --fail --silent -H "App-Key: A4E247A48AAF12BF2E97D9F346E56" https://admin.libertybus.je/api/v1/soj/stop_updates/${stop}) exitcode=$? # sort livetimes by service_number and eta livetimes=$(echo ${livetimes} | jq 'sort_by((.service_number | sub("[^0-9]$"; "") | tonumber), (.service_number | sub("[^A-Z]$"; "") | tostring), .eta)') livetimeslen=$(echo ${livetimes} | jq '. | length') if [ $exitcode != 0 ]; then - echo "cURL error - exiting." - exit 1 + _curlerror elif [ $livetimeslen = 0 ]; then echo "No results found." exit 1 @@ -41,13 +40,12 @@ _liveresult() { } _stopsreturn() { - stops=$(curl --fail --silent https://admin.libertybus.je/api/v1/stops/"${stop}") + stops=$(curl --fail --silent -H "App-Key: A4E247A48AAF12BF2E97D9F346E56" https://admin.libertybus.je/api/v1/stops/"${stop}") exitcode=$? stopslen=$(echo ${stops} | jq '. | length') # if length of $stops array is 1 then only one bus stop matches and we can return live times for that stop if [ $exitcode != 0 ]; then - echo "cURL error - exiting." - exit 1 + _curlerror elif [ $stopslen = 1 ]; then stop=$(echo ${stops} | jq '.[].stop_id') _liveresult @@ -77,6 +75,11 @@ _help() { exit 0 } +_curlerror() { + echo "cURL error $exitcode - exiting." + exit 1 +} + _nextbus() { if [ -z ${time} ]; then time=$(date +"%H:%M") @@ -120,7 +123,7 @@ _nextbus() { exit 1 } -timetables=$(curl --fail --silent https://admin.libertybus.je/cache/timetables/timetable_full.json) +timetables=$(curl --fail --silent -H "App-Key: A4E247A48AAF12BF2E97D9F346E56" https://admin.libertybus.je/cache/timetables/timetable_full.json) services=$(echo $timetables | jq '.timetables[].service_number') if [ "$stop" == "-h" ] || [ "$stop" == "--help" ] || [[ -z "${stop// }" ]]; then _help -- cgit v1.2.3