summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsa Venton <asav1410@gmail.com>2019-10-20 18:36:12 +0100
committerAsa Venton <asav1410@gmail.com>2019-10-20 18:50:42 +0100
commitd8ccaf59ad849d9f539df2cb37c35d458904b56b (patch)
tree64fbf4495c5c8751484129191e12757903338f98
parentd4c5c1c082aaaa75b87268223dcf2653b7b5a9a5 (diff)
Refactor _liveresult()
-rwxr-xr-xlivetimes.sh37
1 files changed, 23 insertions, 14 deletions
diff --git a/livetimes.sh b/livetimes.sh
index 9c9d7bd..f2702f5 100755
--- a/livetimes.sh
+++ b/livetimes.sh
@@ -11,21 +11,30 @@ _jq() {
# TODO: efficiency of _liveresult?
_liveresult() {
livetimes=$(curl --silent https://admin.libertybus.je/api/v1/soj/stop_updates/${stop})
- result="$result Dest: "
- for json in $(echo "${livetimes}" | jq -r '.[] | @base64'); do
- 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'), "
+ 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/,$//')
done
+
echo -e $result
exit 0
}
@@ -33,7 +42,7 @@ _liveresult() {
_stopsreturn() {
stops=$(curl --silent https://admin.libertybus.je/api/v1/stops/"${stop}" | jq -r '.')
stopslen=$(echo ${stops} | jq '. | length')
- # if length of $stops array is 1 then only one bus stop matches and we can return live tiems for that stop
+ # if length of $stops array is 1 then only one bus stop matches and we can return live times for that stop
if [ $stopslen = 1 ]; then
stop=$(echo ${stops} | jq '.[].stop_id')
_liveresult