-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.php
83 lines (69 loc) · 2.83 KB
/
index.php
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
require "./vendor/autoload.php";
use Dotenv\Dotenv;
use EScooters\Importers\BirdDataImporter;
use EScooters\Importers\BoltDataImporter;
use EScooters\Importers\DataImporter;
use EScooters\Importers\DottDataImporter;
use EScooters\Importers\HelbizDataImporter;
use EScooters\Importers\LimeDataImporter;
use EScooters\Importers\LinkDataImporter;
use EScooters\Importers\NeuronDataImporter;
use EScooters\Importers\QuickDataImporter;
use EScooters\Importers\SpinDataImporter;
use EScooters\Importers\TierDataImporter;
use EScooters\Importers\VoiDataImporter;
use EScooters\Importers\WhooshDataImporter;
use EScooters\Models\Repositories\Cities;
use EScooters\Models\Repositories\Countries;
use EScooters\Models\Repositories\Providers;
use EScooters\Services\MapboxGeocodingService;
use EScooters\Services\QuickChartIconsService;
use EScooters\Utils\BuildInfo;
Dotenv::createImmutable(__DIR__)->load();
$token = $_ENV["VUE_APP_MAPBOX_TOKEN"];
$cities = new Cities();
$countries = new Countries();
$providers = new Providers();
/** @var array<DataImporter> $dataImporters */
$dataImporters = [
new BoltDataImporter($cities, $countries),
new LimeDataImporter($cities, $countries),
new QuickDataImporter($cities, $countries),
new TierDataImporter($cities, $countries),
new VoiDataImporter($cities, $countries),
new LinkDataImporter($cities, $countries),
new SpinDataImporter($cities, $countries),
new NeuronDataImporter($cities, $countries),
new HelbizDataImporter($cities, $countries),
new WhooshDataImporter($cities, $countries),
new BirdDataImporter($cities, $countries),
new DottDataImporter($cities, $countries),
];
$timestamp = date("Y-m-d H:i:s");
echo "Build date: $timestamp" . PHP_EOL . PHP_EOL;
foreach ($dataImporters as $dataImporter) {
try {
$provider = $dataImporter->extract()->transform()->load();
} catch (Throwable $exception) {
echo $exception->getMessage() . PHP_EOL;
continue;
}
$providers->add($provider);
echo "{$provider->getCities()->count()} cities fetched for {$provider->getName()}." . PHP_EOL;
}
$count = count($cities->all());
echo PHP_EOL . "$count cities fetched." . PHP_EOL;
$mapbox = new MapboxGeocodingService($token);
$mapbox->setCoordinatesToCities($cities);
$mapbox = new QuickChartIconsService();
$mapbox->generateCityIcons($cities);
$info = new BuildInfo(
timestamp: $timestamp,
citiesCount: $count,
providersCount: count($providers->jsonSerialize()),
);
file_put_contents("./public/data/cities.json", json_encode($cities, JSON_UNESCAPED_UNICODE));
file_put_contents("./public/data/countries.json", json_encode($countries, JSON_UNESCAPED_UNICODE));
file_put_contents("./public/data/providers.json", json_encode($providers, JSON_UNESCAPED_UNICODE));
file_put_contents("./public/data/info.json", json_encode($info, JSON_UNESCAPED_UNICODE));