summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xlivetimes.sh21
1 files changed, 16 insertions, 5 deletions
diff --git a/livetimes.sh b/livetimes.sh
index 55d143f..e6ec3fe 100755
--- a/livetimes.sh
+++ b/livetimes.sh
@@ -1,6 +1,6 @@
#!/bin/bash
# TODO: If $stop similar to "Bus Station" then reject and suggest user tries supplying a route number to see when their next bus leaves the station
-# TODO: Fix space at the start of new lines in result
+# TODO: Fix duplication of destinations and routes in result
read stop
# function to provide data to a for loop
@@ -11,10 +11,20 @@ _jq() {
_liveresult() {
livetimes=$(curl --silent https://admin.libertybus.je/api/v1/soj/stop_updates/${stop})
# doesn't work without encoding in base64 (why?)
+ result="$result Dest: "
for json in $(echo "${livetimes}" | jq -r '.[] | @base64'); do
- result="$result Dest: $(_jq '.destination') |"
- result="$result ETA: $(_jq '.eta') |"
- result="$result Route: $(_jq '.service_number')\n"
+ result="$result $(_jq '.destination'), "
+ done
+ result=$(echo $result | sed 's/,$//')
+ result="$result | Routes:"
+ for json in $(echo "${livetimes}" | jq -r '.[] | @base64'); do
+ result="$result $(_jq '.service_number'), "
+ done
+ result=$(echo $result | sed 's/,$//')
+ result="$result | ETAs: "
+ for json in $(echo "${livetimes}" | jq -r '.[] | @base64'); do
+ result="$result $(_jq '.eta'), "
+ result=$(echo $result | sed 's/, $//')
done
echo -e $result
exit 0
@@ -34,8 +44,9 @@ _stopsreturn() {
else
for json in $(echo "${stops}" | jq -r '.[] | @base64'); do
result="$result Stop: $(_jq '.name') |"
- result="$result Code: $(_jq '.stop_id')\n"
+ result="$result Code: $(_jq '.stop_id') |"
done
+ result=$(echo $result | sed 's/ |$//')
echo -e $result
exit 0
fi