summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsa Venton <asav1410@gmail.com>2019-10-22 20:33:48 +0100
committerAsa Venton <asav1410@gmail.com>2019-10-22 20:33:48 +0100
commitd637ce2f84247f08e9fe1c193581fad07061979d (patch)
tree329b7ae2cb53301f757d00dfb9acf7177238641e
parenta5b8bfa02e99031d540dfa98909056f21731a822 (diff)
Fix next bus returning nothing if the next bus is tomorrow
-rwxr-xr-xlivetimes.sh4
1 files changed, 3 insertions, 1 deletions
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^^})