diff options
author | Asa Venton <asav1410@gmail.com> | 2019-10-21 21:28:32 +0100 |
---|---|---|
committer | Asa Venton <asav1410@gmail.com> | 2019-10-21 21:28:32 +0100 |
commit | 5040a82cde4be1daeea8cdf1830c4fcb12798224 (patch) | |
tree | 4ef6c174160526de9b2ed7562d18aa531ce2f283 /livetimes.sh | |
parent | 2186eed1de3efd0e5d084c72f761e586e789ee46 (diff) |
Adjust output formatting
Diffstat (limited to 'livetimes.sh')
-rwxr-xr-x | livetimes.sh | 36 |
1 files changed, 14 insertions, 22 deletions
diff --git a/livetimes.sh b/livetimes.sh index 8c783a6..2427dde 100755 --- a/livetimes.sh +++ b/livetimes.sh @@ -10,8 +10,10 @@ _jq() { _liveresult() { livetimes=$(curl --fail --silent https://admin.libertybus.je/api/v1/soj/stop_updates/${stop}) - jq '.[]|=sort_by(.service_number)' > sorted.json exitcode=$? + # sort livetimes by service_number and eta + livetimes=$(echo ${livetimes} | jq 'sort_by((.service_number | sub("[^0-9]$"; "") | tonumber), (.service_number | sub("[^A-Z]$"; "") | tostring), .eta)') + #livetimes=$(echo ${livetimes} | jq 'sort_by((.service_number | [ (sub("[^0-9]*$"; "") | tonumber), sub("^[0-9]*"; "") ]), .eta))' livetimeslen=$(echo ${livetimes} | jq '. | length') if [ $exitcode != 0 ]; then echo "cURL error - exiting." @@ -20,26 +22,16 @@ _liveresult() { echo "No results found." exit 1 else - outtypes=(destination service_number eta) - for type in ${outtypes[@]}; do - case $type in - destination) - result="$result Dest:" - ;; - service_number) - result="$result | Routes:" - ;; - eta) - result="$result | ETAs: " - ;; - *) - ;; - esac - for json in $(echo "${livetimes}" | jq -r '.[] | @base64'); do - result="$result $(_jq '.'$type''), " - done - result=$(echo $result | sed 's/,$//') + for json in $(echo "${livetimes}" | jq -r '.[] | @base64'); do + if [[ $(_jq '.service_number') != $outroute ]]; then + result=$(echo $result | sed 's/|//') + result="$result | $(_jq '.destination')[$(_jq '.service_number')] - $(_jq '.eta'), " + elif [ $outroute = $outroute ]; then + result="$result $(_jq '.eta'), " + fi + outroute=$(_jq '.service_number') done + result=$(echo $result | sed 's/,$//' | sed 's/|//' ) echo -e $result exit 0 fi @@ -62,8 +54,8 @@ _stopsreturn() { # multiple stops returned in $stops so we will return stop names and codes so user can retry else for json in $(echo "${stops}" | jq -r '.[] | @base64'); do - result="$result Stop: $(_jq '.name') -" - result="$result Code: $(_jq '.stop_id') |" + result="$result Stop: $(_jq '.name') - Code: $(_jq '.stop_id') |" + #result="$result Code: $(_jq '.stop_id') |" done result=$(echo $result | sed 's/ |$//') echo -e $result |