summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xlivetimes.sh10
1 files changed, 8 insertions, 2 deletions
diff --git a/livetimes.sh b/livetimes.sh
index 5de5563..fd2ded5 100755
--- a/livetimes.sh
+++ b/livetimes.sh
@@ -93,14 +93,20 @@ _nextbus() {
# select all stops from todays trips, where days_of_operation is true for tday, for a given service_number, where stop_name contains "Bus Station Stand"
nextbus=$(echo $timetables | jq -r --arg routeday "$routeday" --arg day "$day" --arg stop "$stop" '.timetables[] | select(.service_number == $stop) | .timetable.outbound[$routeday].trips[] | select(.days_of_operation[$day] == true) | .stops[] | select(.stop_name | contains("Bus Station Stand"))')
for json in $(echo "${nextbus}" | jq -r '. | @base64'); do
- if [[ $(_jq '.departure_time') > $time ]]; then
+ departuretime=$(_jq '.departure_time' | sed s/://g)
+ time=$(echo $time | sed s/://g)
+ # if we allow midnight then day rollover could get messed up (e.g. 00:00 is specified on a Friday then it'll find next bus after 00:00 on Friday and not Saturday)
+ if [[ $time == "0000" ]]; then
+ time=2359
+ fi
+ if [[ ${departuretime#0} -ge ${time#0} ]]; then
echo "Next route "$stop $futuretime"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 on a future day so we need to check future days, unfortunately plenty of routes have days where no bus runs so we need to loop until we find the next day with a running bus
# for loop in range 7 used to prevent possible infinite loop with other methods - if there's not a bus for the next week then something is probably broken
- for in in {1..7}; do
+ for i in {1..7}; do
day=$(date --date="$i day" +"%a" | tr [:upper:] [:lower:])
case $day in
mon|tue|wed|thu|fri)