Added timezones

This commit is contained in:
2026-04-04 19:03:47 +10:00
parent 30b56ece8a
commit 7f62c31456
@@ -19,24 +19,38 @@ class PopulateAirportTimezones extends Command
{ {
Airport::whereNull('timezone')->chunk(100, function ($airports) { Airport::whereNull('timezone')->chunk(100, function ($airports) {
foreach ($airports as $airport) { foreach ($airports as $airport) {
$response = Http::withoutVerifying() $zoneName = null;
->withOptions(['allow_redirects' => false]) $attempts = 0;
->get('http://api.timezonedb.com/v2.1/get-time-zone', [
'key' => config('app.timezone_api_key'),
'format' => 'json',
'by' => 'position',
'lat' => $airport->latitude_deg,
'lng' => $airport->longitude_deg,
]);
if ($response->ok()) { while ($zoneName === null && $attempts < 3) {
$airport->update(['timezone' => $response->json('zoneName')]); $response = Http::withoutVerifying()
} else { ->withOptions(['allow_redirects' => false])
dd($response->json()); ->get('http://vip.timezonedb.com/v2.1/get-time-zone', [
'key' => config('app.timezone_api_key'),
'format' => 'json',
'by' => 'position',
'lat' => $airport->latitude_deg,
'lng' => $airport->longitude_deg,
]);
$zoneName = $response->json('zoneName');
$attempts++;
if ($zoneName === null) {
$this->warn("{$airport->name} — attempt {$attempts} failed: " . $response->body());
sleep(5);
}
} }
sleep(1); if ($zoneName) {
$airport->update(['timezone' => $zoneName]);
$this->info("{$airport->name}{$zoneName}");
} else {
$this->warn("{$airport->name} — giving up after {$attempts} attempts");
}
} }
}); });
$this->info('Done!');
} }
} }