diff options
-rwxr-xr-x | livetimes.sh | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/livetimes.sh b/livetimes.sh index 9c9d7bd..f2702f5 100755 --- a/livetimes.sh +++ b/livetimes.sh @@ -11,21 +11,30 @@ _jq() { # TODO: efficiency of _liveresult? _liveresult() { livetimes=$(curl --silent https://admin.libertybus.je/api/v1/soj/stop_updates/${stop}) - result="$result Dest: " - for json in $(echo "${livetimes}" | jq -r '.[] | @base64'); do - result="$result $(_jq '.destination'), " - done - result=$(echo $result | sed 's/,$//') - result="$result | Routes:" - for json in $(echo "${livetimes}" | jq -r '.[] | @base64'); do - result="$result $(_jq '.service_number'), " - done - result=$(echo $result | sed 's/,$//') - result="$result | ETAs: " - for json in $(echo "${livetimes}" | jq -r '.[] | @base64'); do - result="$result $(_jq '.eta'), " + outtypes=(destination service_number eta) + for type in ${outtypes[@]}; do + case $type in + + destination) + result="$result Dest: " + ;; + + service_number) + result="$result | Routes:" + ;; + + eta) + result="$result | ETAs: " + ;; + *) + ;; + esac + for json in $(echo "${livetimes}" | jq -r '.[] | @base64'); do + result="$result $(_jq '.'$type''), " + done result=$(echo $result | sed 's/,$//') done + echo -e $result exit 0 } @@ -33,7 +42,7 @@ _liveresult() { _stopsreturn() { stops=$(curl --silent https://admin.libertybus.je/api/v1/stops/"${stop}" | jq -r '.') stopslen=$(echo ${stops} | jq '. | length') - # if length of $stops array is 1 then only one bus stop matches and we can return live tiems for that stop + # if length of $stops array is 1 then only one bus stop matches and we can return live times for that stop if [ $stopslen = 1 ]; then stop=$(echo ${stops} | jq '.[].stop_id') _liveresult |