Repository navigation
Expand file tree
/
Copy pathstations.php
More file actions
60 lines (43 loc) · 1.62 KB
/
Copy pathstations.php
File metadata and controls
60 lines (43 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
declare(strict_types=1);
/**
* Поиск кодов станций
*
* Код станции нужен для всех остальных запросов
*/
require __DIR__ . '/bootstrap.php';
$client = rzd();
$query = $argv[1] ?? 'ЧЕБ';
$stations = attempt(fn() => $client->stations->suggest($query));
heading(sprintf('Подсказки по запросу «%s»: %d', $query, count($stations)));
foreach ($stations as $station) {
printf(
"%s %-9s %s %s %s\n",
pad($station->name, 24),
$station->code,
pad($station->type, 16),
pad($station->timezone, 20),
implode(', ', $station->stationCodes),
);
}
heading('Первая подходящая станция без разбора списка');
$found = attempt(fn() => $client->stations->find($query));
printf("%s %s\n", pad($found?->name, 24), $found?->code);
heading('Коды смежных видов транспорта у первой станции');
foreach ($stations[0]->codes as $type => $code) {
printf("%-10s %s\n", $type, $code);
}
heading('Популярные города');
foreach (array_slice(attempt(fn() => $client->stations->popular()), 0, 10) as $city) {
printf("%s %-9s %s\n", pad($city->name, 20), $city->code, $city->nodeId);
}
heading('Популярные направления');
foreach (attempt(fn() => $client->stations->directions()) as $direction) {
printf(
"%s → %s %s → %s\n",
pad($direction->origin?->name, 18),
pad($direction->destination?->name, 18),
$direction->origin?->code,
$direction->destination?->code,
);
}