Improved www.ttss.krakow.pl
Jacek Kowalski
2019-02-09 d06aef5ada4cf248ebe549c4d4ba6b89e8c3be07
commit | author | age
ced309 1 <?php
JK 2 if(php_sapi_name() !== 'cli') die();
3
cbce8b 4 function fetchStops($url) {
JK 5     $json = file_get_contents($url);
6     $elements = json_decode($json, 1);
7     $stops = [];
8     foreach($elements['stops'] as $element) {
9         if($element['category'] == 'other') continue;
10         $stops[$element['shortName']] = $element['name'];
11     }
12     asort($stops);
13     return $stops;
ced309 14 }
JK 15
cbce8b 16 function printStops($stops, $prefix) {
JK 17     foreach($stops as $id => $stop) {
18         echo '  \''.$prefix.str_pad($id."'", 5, ' ', STR_PAD_RIGHT).' => '.var_export($stop, TRUE).','."\n";
19     }
20 }
21
22 $stops_tram = fetchStops('http://www.ttss.krakow.pl/internetservice/geoserviceDispatcher/services/stopinfo/stops?left=-648000000&bottom=-324000000&right=648000000&top=324000000');
23 $stops_bus = fetchStops('http://91.223.13.70/internetservice/geoserviceDispatcher/services/stopinfo/stops?left=-648000000&bottom=-324000000&right=648000000&top=324000000');
f7c4c3 24
JK 25 echo '<?php'."\n";
26 echo '$stops = array ('."\n";
cbce8b 27 printStops($stops_tram, 't');
JK 28 echo "\n";
29 printStops($stops_bus, 'b');
f7c4c3 30 echo ');'."\n";