diff options
Diffstat (limited to 'livetimes.sh')
-rwxr-xr-x | livetimes.sh | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/livetimes.sh b/livetimes.sh index 1235786..384466f 100755 --- a/livetimes.sh +++ b/livetimes.sh @@ -78,21 +78,22 @@ _help() { _nextbus() { time=$(date +"%H:%M") + day=$(date +"%a" | tr [:upper:] [:lower:]) # set day to one of three timetable options if [[ $(date +%u) -lt 6 ]]; then - day=mon_fri + routeday=mon_fri else - day=$(date +"%a") + routeday=$(date +"%a" | tr [:upper:] [:lower:]) 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"))') + # 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 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 + # 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 - this is probably wrong if the day is Friday, Saturday or Sunday as timetables switch on those days. echo $(echo "Route $stop leaving from $(echo $nextbus | jq -s '.[0].stop_name') at $(echo $nextbus | jq -s '.[0].departure_time') tomorrow" | sed 's/"//g') exit 0 } @@ -107,7 +108,7 @@ elif [[ "$stop" =~ ^-?[0-9]+$ ]] && [ $(echo ${#stop} == 4) ]; then # checks if input is a valid bus route elif [[ ${services[@]} =~ ${stop^^} ]]; then _nextbus -elif [[ ${stop,,} == *"bus"* ]] || [[ ${stop,,} == *"stationg"* ]] || [[ ${stop,,} == *"stand"* ]]; then +elif [[ ${stop,,} == *"bus"* ]] || [[ ${stop,,} == *"station"* ]] || [[ ${stop,,} == *"stand"* ]]; then _rejectbusstation else _stopsreturn |