From bf914a5ed0a5173dea527aa0dc319ae3425018a3 Mon Sep 17 00:00:00 2001 From: Asa Venton Date: Fri, 18 Oct 2019 21:07:50 +0100 Subject: initial commit --- README.md | 0 getjson.sh | 25 +++++++++++ index.php | 146 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 171 insertions(+) create mode 100644 README.md create mode 100755 getjson.sh create mode 100644 index.php diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/getjson.sh b/getjson.sh new file mode 100755 index 0000000..3ff6080 --- /dev/null +++ b/getjson.sh @@ -0,0 +1,25 @@ +#!/bin/bash +if [ ! -f ./timetable_full.json ]; then + curl https://admin.libertybus.je/cache/timetables/timetable_full.json > ./timetable_full.json + md5sum ./timetable_full.json | cut -f1 -d ' ' > timetable_full.json.md5hash.txt +else + curl https://admin.libertybus.je/cache/timetables/timetable_full.json > ./timetable_full.new.json + newHash=`md5sum timetable_full.new.json | cut -f1 -d ' '` + if [ $newHash != ./timetable_full.json.md5hash.txt ]; then + rm ./timetable_full.json && rm ./timetable_full.json.md5hash.txt + mv ./timetable_full.new.json ./timetable_full.json + echo "$newHash" > ./timetable_full.json.md5hash.txt + fi +fi +if [ ! -f ./service_updates.json ]; then + curl https://admin.libertybus.je/api/v1/service_updates > ./service_updates.json + md5sum ./service_updates.json | cut -f1 -d ' ' > service_updates.json.md5hash.txt +else + curl https://admin.libertybus.je/api/v1/service_updates > ./service_updates.new.json + newHash=`md5sum service_updates.new.json | cut -f1 -d ' '` + if [ $newHash != ./service_updates.json.md5hash.txt ]; then + rm ./service_updates.json && rm ./service_updates.json.md5hash.txt + mv ./service_updates.new.json ./service_updates.json + echo "$newHash" > ./service_updates.json.md5hash.txt + fi +fi diff --git a/index.php b/index.php new file mode 100644 index 0000000..13f03af --- /dev/null +++ b/index.php @@ -0,0 +1,146 @@ + + + + +bus.of.je + + + + + +

bus.of.je | Liberty Bus Timetables

+ +'. $schedule['service_number'] . ' - ' . $schedule['service_name'] . ''; + + // print service updates for current timetable + foreach ($servUpdates as $update) { + if(in_array($route, $update['services'])) { + array_push($routeUpdates, $update['content']); + } + } + if (!empty($routeUpdates)) { + echo '

Service Updates:

'; + foreach ($routeUpdates as $update) { + echo $update . '
'; + } + } + // print timetables + foreach ($days as $day) { + if ($schedule['schedule'][$day] == 'true') { + // set display friendly variables for days + switch ($day){ + case "mon_fri": + $displayDay = "Mon - Fri"; + break; + case "sat": + $displayDay = "Saturday"; + break; + case "sun": + $displayDay = "Sunday"; + break; + default: + break; + } + foreach ($directions as $direction) { + if ($schedule['directions'][$direction] == 'true') { + $stopList = getData('stoplist', $route, $direction, false); + // print timetable info while setting display friendly case for directions + // TODO: add linebreaks between end of table and next table title + echo '


' . ucfirst($direction) . ' | ' . $displayDay . ''; + echo ''; + $trips = getData('trips', $route, $direction, $day); + // TODO: sort stopList by stopList['order'] + // TODO: must be a more efficient way to search for $rowStop['stop_name'] in $trip? + foreach ($stopList as $rowStop) { + echo ''; + foreach ($trips as $trip) { + $found=False; + foreach ($trip['stops'] as $stop) { + if ($stop['stop_name'] == $rowStop['stop_name']) { + echo ''; + $found=True; + } + } + // print something to show bus doesn't use this stop on this trip e.g. route variation + if ($found != True) { + echo ''; + } + } + echo ''; + } + echo '
' . $rowStop['stop_name'] . '' . $stop['departure_time'] . '----


'; + } + } + } + } +} +// print landing page if no route is selected +else { + $routes = getData('routes', false, false, false); + $meta = getData('meta', false, false, false); + echo '

' . $meta['name']. ' | ' . $meta['from'] . ' - ' . $meta['to'] . '

'; + echo '

Service Updates:

\n

'; + foreach ($servUpdates as $update) { + echo $update['content'] . '- Affected Routes: ' . implode(", ",$update['services']) . '

'; + } + foreach ($routes as $route) { + echo '

' . $route['service_number'] . ' - ' . $route['service_name'] . '

'; + } + echo '

'; +} +?> + +

+ + + -- cgit v1.2.3