summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsa Venton <asav1410@gmail.com>2019-10-22 23:56:36 +0100
committerAsa Venton <asav1410@gmail.com>2019-10-22 23:56:36 +0100
commit933513d03daf5b3f040266f9a2f83a51bdf338c8 (patch)
treea02ff25323b7aff318ba4d851882cbaec194b265
parentced31d59844813c7a863e2d78676cd494baafac8 (diff)
Add check for days of service (some routes have Friday only buses)
-rwxr-xr-xlivetimes.sh13
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