Added timezones
This commit is contained in:
@@ -19,9 +19,13 @@ class PopulateAirportTimezones extends Command
|
||||
{
|
||||
Airport::whereNull('timezone')->chunk(100, function ($airports) {
|
||||
foreach ($airports as $airport) {
|
||||
$zoneName = null;
|
||||
$attempts = 0;
|
||||
|
||||
while ($zoneName === null && $attempts < 3) {
|
||||
$response = Http::withoutVerifying()
|
||||
->withOptions(['allow_redirects' => false])
|
||||
->get('http://api.timezonedb.com/v2.1/get-time-zone', [
|
||||
->get('http://vip.timezonedb.com/v2.1/get-time-zone', [
|
||||
'key' => config('app.timezone_api_key'),
|
||||
'format' => 'json',
|
||||
'by' => 'position',
|
||||
@@ -29,14 +33,24 @@ class PopulateAirportTimezones extends Command
|
||||
'lng' => $airport->longitude_deg,
|
||||
]);
|
||||
|
||||
if ($response->ok()) {
|
||||
$airport->update(['timezone' => $response->json('zoneName')]);
|
||||
} else {
|
||||
dd($response->json());
|
||||
$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!');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user