diff --git a/index.php b/index.php index 87a244f..afad904 100644 --- a/index.php +++ b/index.php @@ -133,28 +133,53 @@ ]; // APIデータを取得 - $content = file_get_contents("https://svc.metrotransit.org/NexTrip/$stop?format=json"); + $content = file_get_contents("https://svc.metrotransit.org/nextripv2/$stop"); $json = json_decode($content); if(isset($json)) { // 情報をプリント - echo "

停留所{$stop}のNexTrip情報

"; + $stop_name = str_replace(' & ', 'と', $json->stops[0]->description); + echo "

停留所{$stop} – $stop_name

"; + echo '
'; - foreach($json as $bus) { - if(strchr($bus->DepartureText, ':')) { - preg_match("/(\d+)000/", $bus->DepartureTime, $matches); - $time = date('H:i', $matches[1]); + foreach($json->departures as $bus) { + if($bus->actual) { + $time = str_replace(" Min", "分", $bus->departure_text); + $time = str_replace("Due", "今すぐ", $time); } else { - $time = preg_replace("/ Min/", "分", $bus->DepartureText); - $time = preg_replace("/Due/", "今すぐ", $time); + $time = date('H:i', $bus->departure_time); } - echo '
'; - echo "

$bus->Route{$bus->Terminal}({$directions[$bus->RouteDirection]})
$time

"; - echo '
'; + $warn = ""; + $warnClass = ""; + if($bus->schedule_relationship == "Skipped") { + $warn = "キャンセル"; + $warnClass = 'text-danger'; + } else if($bus->schedule_relationship == "NoData") { + $warn = "データなし"; + $warnClass = 'text-warning'; + } else if($bus->schedule_relationship != "Scheduled") { + $warn = $bus->schedule_relationship; + $warnClass = 'text-warning'; + } + + echo "

"; + $route_name = str_replace(' Line', '線', $bus->route_short_name) . $bus->terminal; + echo "{$route_name}({$directions[$bus->direction_text]})"; + echo "
$time"; + if($warn) + echo "
$warn"; + echo '

'; } echo '
'; + if($json->alerts) + echo '

アラート

'; + foreach($json->alerts as $alert) { + $alertClass = $alert->stop_closed ? "alert-danger" : "alert-warning"; + echo "
$alert->alert_text
"; + } + if(!empty($key)) { // お気に入りフォームをプリント $query = 'SELECT description FROM favorites WHERE favorites.key=$1 AND favorites.stop=$2 LIMIT 1';