From 7f62c3145625a03f2bd025f7bc9864a71e9964da Mon Sep 17 00:00:00 2001 From: josh Date: Sat, 4 Apr 2026 19:03:47 +1000 Subject: [PATCH] Added timezones --- .../Commands/PopulateAirportTimezones.php | 42 ++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/app/Console/Commands/PopulateAirportTimezones.php b/app/Console/Commands/PopulateAirportTimezones.php index 08927f3..cd1e116 100644 --- a/app/Console/Commands/PopulateAirportTimezones.php +++ b/app/Console/Commands/PopulateAirportTimezones.php @@ -19,24 +19,38 @@ class PopulateAirportTimezones extends Command { Airport::whereNull('timezone')->chunk(100, function ($airports) { foreach ($airports as $airport) { - $response = Http::withoutVerifying() - ->withOptions(['allow_redirects' => false]) - ->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, - ]); + $zoneName = null; + $attempts = 0; - if ($response->ok()) { - $airport->update(['timezone' => $response->json('zoneName')]); - } else { - dd($response->json()); + while ($zoneName === null && $attempts < 3) { + $response = Http::withoutVerifying() + ->withOptions(['allow_redirects' => false]) + ->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!'); } }