From d637ce2f84247f08e9fe1c193581fad07061979d Mon Sep 17 00:00:00 2001 From: Asa Venton Date: Tue, 22 Oct 2019 20:33:48 +0100 Subject: Fix next bus returning nothing if the next bus is tomorrow --- livetimes.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/livetimes.sh b/livetimes.sh index d4bd050..209bec8 100755 --- a/livetimes.sh +++ b/livetimes.sh @@ -77,13 +77,15 @@ _nextbus() { fi # select all stops from todays trips for a given service_number where stop_name contains "Bus Station Stand" nextbus=$(echo $timetables | jq -r --arg day "$day" --arg stop "$stop" '.timetables[] | select(.service_number == $stop) | .timetable.outbound[$day].trips[].stops[] | select(.stop_name | contains("Bus Station Stand"))') - echo $nextbus > foo.json for json in $(echo "${nextbus}" | jq -r '. | @base64'); do if [[ $(_jq '.departure_time') > $time ]]; then echo "Route $stop leaving from $(_jq '.stop_name') at $(_jq '.departure_time')" exit 0 fi done + # if program didn't exit inside for loop then we know the next bus is actually tomorrow in which case we'll return the zeroth item of the array + echo $(echo "Route $stop leaving from $(echo $nextbus | jq -s '.[0].stop_name') at $(echo $nextbus | jq -s '.[0].departure_time')" | sed 's/"//g') + exit 0 } #stop=$(echo ${stop^^}) -- cgit v1.2.3