Added timezones
This commit is contained in:
@@ -6,9 +6,10 @@ use App\Models\Airport;
|
|||||||
use Illuminate\Console\Attributes\Description;
|
use Illuminate\Console\Attributes\Description;
|
||||||
use Illuminate\Console\Attributes\Signature;
|
use Illuminate\Console\Attributes\Signature;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
|
||||||
#[Signature('app:populate-airport-timezones')]
|
#[Signature('app:populate-airport-timezones')]
|
||||||
#[Description('Command description')]
|
#[Description('Populate timezone data for all airports using lat/lng')]
|
||||||
class PopulateAirportTimezones extends Command
|
class PopulateAirportTimezones extends Command
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@@ -18,16 +19,20 @@ 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::get('http://api.timezonedb.com/v2.1/get-timezone', [
|
$response = Http::withoutVerifying()
|
||||||
'key' => config('app.timezone_db_key'),
|
->withOptions(['allow_redirects' => false])
|
||||||
|
->get('http://api.timezonedb.com/v2.1/get-time-zone', [
|
||||||
|
'key' => config('app.timezone_api_key'),
|
||||||
'format' => 'json',
|
'format' => 'json',
|
||||||
'by' => 'position',
|
'by' => 'position',
|
||||||
'lat' => $airport->latitude,
|
'lat' => $airport->latitude_deg,
|
||||||
'lng' => $airport->longitude,
|
'lng' => $airport->longitude_deg,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($response->ok()) {
|
if ($response->ok()) {
|
||||||
$airport->update(['timezone' => $response->json('zoneName')]);
|
$airport->update(['timezone' => $response->json('zoneName')]);
|
||||||
|
} else {
|
||||||
|
dd($response->json());
|
||||||
}
|
}
|
||||||
|
|
||||||
sleep(1);
|
sleep(1);
|
||||||
|
|||||||
Reference in New Issue
Block a user