private static function getVehicleData($serverData, $id, $lang){ // determine the location of the vehicle preg_match("/=>(\d\d:\d\d)( \+(\d\d?)')? <a href=\"\/mobile\/SearchStation.*? >(.*?)<\/a>/smi", $serverData, $matches); $locationX = 0; $locationY = 0; if(isset($matches[4])){ $now = stations::getStationFromRTName($matches[4], $lang); $locationX = $now -> locationX; $locationY = $now -> locationY; } $vehicle = new Vehicle(); $vehicle->name = $id; $vehicle->locationX = $locationX; $vehicle->locationY = $locationY; return $vehicle; }
private static function getVehicleData($serverData, $id, $lang){ // determine the location of the vehicle $html = str_get_html($serverData); $nodes = $html->find("td[class*=TrainReperage]"); if ($nodes) { $station = $nodes[0]->parent()->children(1)->first_child()->plaintext; } $locationX = 0; $locationY = 0; if(isset($station)){ $now = stations::getStationFromRTName($station, $lang); $locationX = $now -> locationX; $locationY = $now -> locationY; } $vehicle = new Vehicle(); $vehicle->name = $id; $vehicle->locationX = $locationX; $vehicle->locationY = $locationY; return $vehicle; }
private static function parseData($html, $time, $lang) { $hour = substr($time, 0, 2); preg_match_all("/<tr>(.*?)<\\/tr>/ism", $html, $m); $nodes = array(); $i = 0; //for each row foreach ($m[1] as $tr) { preg_match("/<td valign=\"top\">(.*?)<\\/td><td valign=\"top\">(.*?)<\\/td>/ism", $tr, $m2); //$m2[1] has: time //$m2[2] has delay, stationname & platform //GET LEFT OR NOT $left = 0; if (preg_match("/color=\"DarkGray\"/ism", $tr, $lll) > 0) { $left = 1; } //GET TIME: preg_match("/((\\d\\d):\\d\\d)/", $m2[1], $t); //if it is 23 pm and we fetched data for 1 hour, we may end up with data for the next day and thus we will need to add a day $dayoffset = 0; if ($t[2] != 23 && $hour == 23) { $dayoffset = 1; } $time = "0" . $dayoffset . "d" . $t[1] . ":00"; $dateparam = date("ymd"); //day is previous day if time is before 4 O clock (NMBS-ish thing) if (date('G') < 4) { $dateparam = date("ymd", strtotime("-1 day")); } $unixtime = tools::transformTime($time, "20" . $dateparam); //GET DELAY $delay = 0; preg_match("/\\+(\\d+)'/", $m2[2], $d); if (isset($d[1])) { $delay = $d[1] * 60; } preg_match("/\\+(\\d):(\\d+)/", $m2[2], $d); if (isset($d[1])) { $delay = $d[1] * 3600 + $d[2] * 60; } //GET STATION preg_match("/.* (.*?) <span/", $m2[2], $st); //echo $st[1] . "\n"; $st = explode("/", $st[1]); $st = trim($st[0]); try { $stationNode = stations::getStationFromRTName(strtoupper($st), $lang); } catch (Exception $e) { //fallback: if no railtime name is available, let's ask HAFAS to solve this issue for us $stationNode = stations::getStationFromName($st, $lang); } //GET VEHICLE AND PLATFORM $platform = ""; $platformNormal = true; preg_match("/\\[(.*?)( .*?)?\\]/", $m2[2], $veh); $vehicle = "BE.NMBS." . $veh[1]; if (isset($veh[2])) { if (preg_match("/<[bf].*?>(.*?)<\\/.*?>/", $veh[2], $p)) { $platform = $p[1]; $platformNormal = false; } else { //echo $veh[2] . "\n"; preg_match("/ .*? (.*)/", $veh[2], $p2); if (isset($p2[1])) { $platform = $p2[1]; } } } $nodes[$i] = new DepartureArrival(); $nodes[$i]->delay = $delay; $nodes[$i]->station = $stationNode; $nodes[$i]->time = $unixtime; $nodes[$i]->vehicle = $vehicle; $nodes[$i]->platform = new Platform(); $nodes[$i]->platform->name = $platform; $nodes[$i]->platform->normal = $platformNormal; $nodes[$i]->left = $left; $i++; } return liveboard::removeDuplicates($nodes); }
private static function parseData($html, $time, $lang) { $hour = substr($time, 0, 2); preg_match_all("/<table class=\"StationList\">(.*?)<\\/table>/ism", $html, $m); $nodes = array(); $i = 0; //for each row foreach ($m[0] as $table) { $left = 0; preg_match_all("/<tr class=(.*?)>(.*?)<\\/tr>/ism", $table, $m2); if ($m2[1][0] == "rowStation trainLeft") { $left = 1; } preg_match_all("/<label>(.*?)<\\/label>/ism", $m2[2][0], $m3); //$m3[1][0] has : time //$m3[1][1] has : stationname preg_match_all("/<label class=\"orange\">(.*?)<\\/label>/ism", $m2[2][0], $delay); preg_match_all("/<label class=\"bold\">(.*?)<\\/label>/ism", $m2[2][0], $platform); preg_match_all("/<a class=\"button cmd blue\" href=(.*?)>><\\/a>/ism", $m2[2][0], $id); $delay = $delay[1][0]; $platform = $platform[1][0]; $id = $id[1][0]; //GET TIME: preg_match("/((\\d\\d):\\d\\d)/", $m3[1][0], $t); //if it is 23 pm and we fetched data for 1 hour, we may end up with data for the next day and thus we will need to add a day $dayoffset = 0; if ($t[2] != 23 && $hour == 23) { $dayoffset = 1; } $time = "0" . $dayoffset . "d" . $t[1] . ":00"; $dateparam = date("ymd"); //day is previous day if time is before 4 O clock (NMBS-ish thing) if (date('G') < 4) { $dateparam = date("ymd", strtotime("-1 day")); } $unixtime = tools::transformTime($time, "20" . $dateparam); //GET DELAY preg_match("/\\+(\\d+)'/", $delay, $d); if (isset($d[1])) { $delay = $d[1] * 60; } preg_match("/\\+(\\d):(\\d+)/", $delay, $d); if (isset($d[1])) { $delay = $d[1] * 3600 + $d[2] * 60; } //GET STATION $st = trim(utf8_encode($m3[1][1])); try { $stationNode = stations::getStationFromRTName(strtoupper($st), $lang); } catch (Exception $e) { //fallback: if no railtime name is available, let's ask HAFAS to solve this issue for us $stationNode = stations::getStationFromName($st, $lang); } //GET VEHICLE AND PLATFORM $platformNormal = true; $veh = explode(";", $id); $veh = explode("=", $veh[2]); $vehicle = "BE.NMBS." . str_replace("&", "", $veh[1]); $nodes[$i] = new DepartureArrival(); $nodes[$i]->delay = $delay; $nodes[$i]->station = $stationNode; $nodes[$i]->time = $unixtime; $nodes[$i]->vehicle = $vehicle; $nodes[$i]->platform = new Platform(); $nodes[$i]->platform->name = $platform; $nodes[$i]->platform->normal = $platformNormal; $nodes[$i]->left = $left; $i++; } return liveboard::removeDuplicates($nodes); }