Added parsing library for Heraklion.
This commit is contained in:
parent
02b96eb5f7
commit
6ee1a86297
6 changed files with 231 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
include 'data.php';
|
||||
include 'libher/libher.php';
|
||||
|
||||
function getStopsOfRoute($id){
|
||||
global $routes;
|
||||
|
|
34
modules/libher/libbusposition.php
Normal file
34
modules/libher/libbusposition.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
function BusPosition($line, $direction){
|
||||
global $lang;
|
||||
$buspositions = DownloadBusposition($line,$direction);
|
||||
|
||||
$GenBusPositions = array();
|
||||
$GenBusPositions_keys = array('line', 'id', 'lat', 'lon');
|
||||
|
||||
foreach ($buspositions as $bp){
|
||||
$GenBusPositions_values = array();
|
||||
|
||||
if ($bp == ''){
|
||||
break;
|
||||
}
|
||||
|
||||
$pieces = explode('-', $bp);
|
||||
|
||||
$id = $pieces[0];
|
||||
if ($id == 'null'){
|
||||
$lat = '';
|
||||
$lon = '';
|
||||
}else{
|
||||
$lat = $pieces[1];
|
||||
$lon = $pieces[2];
|
||||
}
|
||||
|
||||
array_push($GenBusPositions_values, $line, $id, $lat, $lon);
|
||||
array_push($GenBusPositions, array_combine($GenBusPositions_keys, $GenBusPositions_values));
|
||||
}
|
||||
return $GenBusPositions;
|
||||
}
|
||||
|
||||
?>
|
85
modules/libher/libdl.php
Normal file
85
modules/libher/libdl.php
Normal file
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
$lang = 'en';
|
||||
|
||||
function DownloadUrl($url){
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url );
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
$output = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
return $output;
|
||||
}
|
||||
function DownloadRouteUIDs(){
|
||||
global $lang;
|
||||
$codes = array();
|
||||
$dom = new DomDocument();
|
||||
@$dom->loadHTML(DownloadUrl('http://astiko-irakleiou.gr/#' . $lang . '/'));
|
||||
|
||||
foreach ($dom->getElementsByTagName('select')[0]->childNodes as $option){
|
||||
$id = $option->getAttribute('value');
|
||||
if ($id == 0){
|
||||
continue;
|
||||
}
|
||||
array_push($codes, $id);
|
||||
}
|
||||
return $codes;
|
||||
}
|
||||
|
||||
function DownloadRouteTitle($id){
|
||||
global $lang;
|
||||
$title = array();
|
||||
$dom = new DomDocument();
|
||||
@$dom->loadHTML(spleet(DownloadUrl('http://astiko-irakleiou.gr/' . $lang . '/routeinfo/list/' . $id . '/?a=1')));
|
||||
$t= utf8_decode($dom->getElementsByTagName('h1')[0]->nodeValue);
|
||||
$pieces = explode(':',$t);
|
||||
$title[0]=array_reverse(explode(' ', $pieces[0]))[0];
|
||||
$title[1]=$pieces[1];
|
||||
|
||||
return $title;
|
||||
|
||||
}
|
||||
|
||||
function DownloadStopName($stp){
|
||||
global $lang;
|
||||
return DownloadUrl('http://astiko-irakleiou.gr/' . $lang . '/stopinfo/getname/' . $stp . '?a=1');
|
||||
}
|
||||
|
||||
function DownloadRouteStops($line,$dir){
|
||||
global $lang;
|
||||
if ($dir == 'go'){
|
||||
$var='a';
|
||||
} else if ($dir == 'come'){
|
||||
$var = 'b';
|
||||
}
|
||||
|
||||
$pieces = explode('/',$line);
|
||||
$stopString = $pieces[0] . '/' . $pieces[1] . '/' . $var . '/';
|
||||
$html = new DomDocument();
|
||||
@$html->loadHTML(DownloadUrl('http://astiko-irakleiou.gr/' . $lang . '/stopinfo/route/' . $stopString . '?a=1'));
|
||||
return $html->getElementsByTagName('option');
|
||||
}
|
||||
|
||||
function DownloadStopInfo($stp){
|
||||
global $lang;
|
||||
return spleet(DownloadUrl('http://astiko-irakleiou.gr/' . $lang . '/stopinfo/screen/' . $stp . '?a=1'));
|
||||
}
|
||||
|
||||
|
||||
function DownloadBusposition($line,$direction){
|
||||
global $lang;
|
||||
$b = spleet(DownloadUrl('http://astiko-irakleiou.gr/' . $lang . '/buspositions/' . $direction . '/' . $line . '?a=1'));
|
||||
$b = preg_replace('/"/i', '', $b);
|
||||
$b = explode('||', $b);
|
||||
return $b;
|
||||
|
||||
}
|
||||
|
||||
function spleet($mrkr) {
|
||||
$z = $mrkr . "";
|
||||
$z = preg_replace("/grZNn/i", '=', $z);
|
||||
$z = base64_decode($z);
|
||||
$z = preg_replace("/!/i", '3', $z);
|
||||
$z = base64_decode($z);
|
||||
return $z;
|
||||
}
|
||||
?>
|
7
modules/libher/libher.php
Normal file
7
modules/libher/libher.php
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
include './libstops.php';
|
||||
include './libroutes.php';
|
||||
include './libdl.php';
|
||||
include './libbusposition.php';
|
||||
|
||||
?>
|
40
modules/libher/libroutes.php
Normal file
40
modules/libher/libroutes.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
function Routes(){
|
||||
global $lang;
|
||||
$GenRoutes = array();
|
||||
$GenRoutes_keys = array('id', 'line', 'name', 'stops');
|
||||
$GenRoutesStop_keys = array('go', 'come');
|
||||
$codes = DownloadRouteUIDs();
|
||||
|
||||
|
||||
# Get each route's name
|
||||
foreach ($codes as $id){
|
||||
$GenRoutes_values = array();
|
||||
$GenRoutesStop_values = array();
|
||||
$title = DownloadRouteTitle($id);
|
||||
$lineCode = $title[0];
|
||||
$lineName = $title[1];
|
||||
|
||||
array_push($GenRoutesStop_values, StopsOfRoute($id,'go'), StopsOfRoute($id,'come'));
|
||||
array_push($GenRoutes_values, $id, $lineCode, $lineName, array_combine($GenRoutesStop_keys, $GenRoutesStop_values));
|
||||
array_push($GenRoutes, array_combine($GenRoutes_keys, $GenRoutes_values));
|
||||
}
|
||||
return $GenRoutes;
|
||||
}
|
||||
|
||||
|
||||
function StopsOfRoute($line,$dir){
|
||||
global $lang;
|
||||
|
||||
$stopsList = array();
|
||||
foreach (DownloadRouteStops($line,$dir) as $stop){
|
||||
$stp = $stop->getAttribute('value');
|
||||
if ($stp == 0){
|
||||
continue;
|
||||
}
|
||||
array_push($stopsList, $stp);
|
||||
}
|
||||
return $stopsList;
|
||||
}
|
||||
|
||||
?>
|
64
modules/libher/libstops.php
Normal file
64
modules/libher/libstops.php
Normal file
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
function StopLoc($stp){
|
||||
$dom = new DOMDocument();
|
||||
@$dom->loadHtml(DownloadStopInfo($stp));
|
||||
$xpath = new DomXPath($dom);
|
||||
$loc = $xpath->query('//div[@class="loc"]')[0]->nodeValue;
|
||||
$loc = explode(',',$loc);
|
||||
return $loc;
|
||||
}
|
||||
|
||||
function ExtractStopIDs(){
|
||||
global $routes;
|
||||
$genStops = array();
|
||||
foreach ($routes as $route){
|
||||
foreach ($route['stops'] as $dir){
|
||||
foreach ($dir as $stp){
|
||||
array_push($genStops,$stp);
|
||||
}
|
||||
}
|
||||
}
|
||||
return uniqueStops($genStops);
|
||||
}
|
||||
|
||||
function GetStops(){
|
||||
$GenStops = array();
|
||||
$GenStops_keys = array('id', 'name', 'lat', 'lon');
|
||||
|
||||
foreach (ExtractStopIDs() as $stp){
|
||||
$GenStops_values = array();
|
||||
|
||||
$loc = StopLoc($stp);
|
||||
$GenStops_values = array($stp, DownloadStopName($stp), $loc[0], $loc[1]);
|
||||
|
||||
array_push($GenStops, array_combine($GenStops_keys, $GenStops_values));
|
||||
}
|
||||
|
||||
usort($GenStops, function($a,$b){
|
||||
return strcmp($a['name'], $b['name']);
|
||||
});
|
||||
return $GenStops;
|
||||
}
|
||||
|
||||
function uniqueStops($list){
|
||||
$unique = array();
|
||||
foreach ($list as $stop){
|
||||
if (foundStop($unique,$stop) == false){
|
||||
array_push($unique, $stop);
|
||||
}
|
||||
}
|
||||
sort($unique);
|
||||
return $unique;
|
||||
}
|
||||
|
||||
function foundStop($haystack,$needle){
|
||||
foreach ($haystack as $l){
|
||||
if ($l == $needle){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
?>
|
Reference in a new issue