commit | author | age
|
ced309
|
1 |
<?php |
JK |
2 |
if(php_sapi_name() !== 'cli') die(); |
|
3 |
|
|
4 |
$chars = 'aąbcćdeęfghijklłmnńoóprsśtuvwxyzżź0123456789'; |
c1a99d
|
5 |
$len = mb_strlen($chars, 'UTF-8'); |
ced309
|
6 |
|
JK |
7 |
$replacements = [ |
|
8 |
'Ó' => 'Ó', |
|
9 |
'ó' => 'ó', |
|
10 |
'É' => 'É', |
|
11 |
'é' => 'é', |
|
12 |
]; |
|
13 |
|
|
14 |
$stops = []; |
|
15 |
for($i = 0; $i < $len; $i++) { |
|
16 |
for($j = 0; $j < $len; $j++) { |
c1a99d
|
17 |
$char = mb_substr($chars, $i, 1, 'UTF-8').mb_substr($chars, $j, 1, 'UTF-8'); |
ced309
|
18 |
$json = file_get_contents('http://www.ttss.krakow.pl/internetservice/services/lookup/autocomplete/json?query='.urlencode($char)); |
JK |
19 |
$elements = json_decode($json, 1); |
|
20 |
foreach($elements as $element) { |
|
21 |
if($element['type'] == 'divider') continue; |
|
22 |
if($element['type'] == 'route') continue; |
|
23 |
if($element['type'] != 'stop') { |
|
24 |
throw new Exception('Unknown element: '.var_export($element, 1)); |
|
25 |
} |
|
26 |
|
|
27 |
$stops[$element['id']] = strtr($element['name'], $replacements); |
|
28 |
} |
|
29 |
} |
|
30 |
} |
|
31 |
|
|
32 |
asort($stops); |
|
33 |
var_export($stops); |