You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.6 KiB
56 lines
1.6 KiB
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Illuminate\Support\Facades\Http;
|
|
use App\Models\CovidData;
|
|
use Carbon\Carbon;
|
|
|
|
class UpdateCovidData implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
/**
|
|
* Create a new job instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Execute the job.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function handle()
|
|
{
|
|
$url = 'https://api.apify.com/v2/datasets/Gm6qjTgGqxkEZTkuJ/items?format=json&clean=1';
|
|
$res = Http::get($url);
|
|
CovidData::whereNotNull('id')->delete();
|
|
foreach ($res->collect() as $data) {
|
|
try {
|
|
$attr = [];
|
|
$attr["infected"] = $data["infected"] ?? null;
|
|
$attr["deceased"] = $data["deceased"] ?? null;
|
|
$attr["recovered"] = $data["recovered"] ?? null;
|
|
$attr["quarantined"] = $data["quarantined"] ?? null;
|
|
$attr["tested"] = $data["tested"] ?? null;
|
|
$attr["created_at"] = Carbon::createFromFormat('Y-m-d\TH:i:s+', $data["lastUpdatedAtApify"]);
|
|
$d = new CovidData($attr);
|
|
$d->save();
|
|
} catch (\Exception $e) {
|
|
dd($data, $e);
|
|
}
|
|
};
|
|
//dd(CovidData::all());
|
|
}
|
|
}
|
|
|