61 lines
2.3 KiB
PHP
61 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\Vehicles;
|
|
|
|
use App\Models\Vehicle;
|
|
use Illuminate\Filesystem\FilesystemAdapter;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class VehicleScraper
|
|
{
|
|
private FilesystemAdapter $filesystem;
|
|
|
|
public function getVehicles()
|
|
{
|
|
$this->filesystem = Storage::disk('pubFiles');
|
|
if (!$this->filesystem->exists('vehicles.json')) {
|
|
dump('File does not exist');
|
|
|
|
return;
|
|
}
|
|
|
|
$vehicles = json_decode($this->filesystem->get('vehicles.json'));
|
|
foreach ($vehicles as $vehicle) {
|
|
Vehicle::updateOrCreate(
|
|
[
|
|
'model' => $vehicle->model,
|
|
],
|
|
[
|
|
'displayName' => $vehicle->displayName,
|
|
'manufacturer' => $vehicle->manufacturer,
|
|
'description' => $vehicle->description ?? '',
|
|
'type' => $vehicle->type,
|
|
'class' => $vehicle->class,
|
|
'isSold' => $vehicle->isSold,
|
|
'price' => $vehicle->price,
|
|
'storage' => $vehicle->storage ?? -1,
|
|
'fuelType' => $vehicle->fuelType,
|
|
'seats' => $vehicle->seats,
|
|
'hash' => $vehicle->hash,
|
|
'signedHash' => $vehicle->signedHash,
|
|
'hexHash' => $vehicle->hexHash,
|
|
'speed' => $vehicle->stats->speed,
|
|
'acceleration' => $vehicle->stats->acceleration,
|
|
'braking' => $vehicle->stats->braking,
|
|
'traction' => $vehicle->stats->traction,
|
|
'length' => $vehicle->dimensions->length,
|
|
'width' => $vehicle->dimensions->width,
|
|
'height' => $vehicle->dimensions->height,
|
|
'topSpeed' => $vehicle->topSpeed,
|
|
'gears' => $vehicle->gears,
|
|
'mass' => $vehicle->mass,
|
|
'driveTrain' => $vehicle->driveTrain,
|
|
'consumption' => $vehicle->consumption,
|
|
'fuelTankVolume' => $vehicle->fuelTankVolume,
|
|
'oilTankVolume' => $vehicle->oilTankVolume,
|
|
'inspiredBy' => $vehicle->inspiredBy,
|
|
]
|
|
);
|
|
}
|
|
}
|
|
} |