summaryrefslogtreecommitdiff
path: root/livetimes.sh
diff options
context:
space:
mode:
Diffstat (limited to 'livetimes.sh')
-rwxr-xr-xlivetimes.sh19
1 files changed, 11 insertions, 8 deletions
diff --git a/livetimes.sh b/livetimes.sh
index c7ce414..4bcfa27 100755
--- a/livetimes.sh
+++ b/livetimes.sh
@@ -9,16 +9,15 @@ _jq() {
}
_liveresult() {
- stops=$(curl --fail --silent https://admin.libertybus.je/api/v1/stops/"${stop}")
+ stops=$(curl --fail --silent -H "App-Key: A4E247A48AAF12BF2E97D9F346E56" https://admin.libertybus.je/api/v1/stops/"${stop}")
stopname=$(echo $stops | jq '.[].name')
- livetimes=$(curl --fail --silent https://admin.libertybus.je/api/v1/soj/stop_updates/${stop})
+ livetimes=$(curl --fail --silent -H "App-Key: A4E247A48AAF12BF2E97D9F346E56" https://admin.libertybus.je/api/v1/soj/stop_updates/${stop})
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)')
livetimeslen=$(echo ${livetimes} | jq '. | length')
if [ $exitcode != 0 ]; then
- echo "cURL error - exiting."
- exit 1
+ _curlerror
elif [ $livetimeslen = 0 ]; then
echo "No results found."
exit 1
@@ -41,13 +40,12 @@ _liveresult() {
}
_stopsreturn() {
- stops=$(curl --fail --silent https://admin.libertybus.je/api/v1/stops/"${stop}")
+ stops=$(curl --fail --silent -H "App-Key: A4E247A48AAF12BF2E97D9F346E56" https://admin.libertybus.je/api/v1/stops/"${stop}")
exitcode=$?
stopslen=$(echo ${stops} | jq '. | length')
# if length of $stops array is 1 then only one bus stop matches and we can return live times for that stop
if [ $exitcode != 0 ]; then
- echo "cURL error - exiting."
- exit 1
+ _curlerror
elif [ $stopslen = 1 ]; then
stop=$(echo ${stops} | jq '.[].stop_id')
_liveresult
@@ -77,6 +75,11 @@ _help() {
exit 0
}
+_curlerror() {
+ echo "cURL error $exitcode - exiting."
+ exit 1
+}
+
_nextbus() {
if [ -z ${time} ]; then
time=$(date +"%H:%M")
@@ -120,7 +123,7 @@ _nextbus() {
exit 1
}
-timetables=$(curl --fail --silent https://admin.libertybus.je/cache/timetables/timetable_full.json)
+timetables=$(curl --fail --silent -H "App-Key: A4E247A48AAF12BF2E97D9F346E56" https://admin.libertybus.je/cache/timetables/timetable_full.json)
services=$(echo $timetables | jq '.timetables[].service_number')
if [ "$stop" == "-h" ] || [ "$stop" == "--help" ] || [[ -z "${stop// }" ]]; then
_help