ConsultancyProject1_Auslast.../scraper/app/Jobs/scrapeProperties.php

56 lines
1.6 KiB
PHP

<?php
namespace App\Jobs;
use App\Models\Seed;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class scrapeProperties implements ShouldQueue, ShouldBeUnique
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $seed;
/**
* Create a new job instance.
*/
public function __construct($seed){
$this->seed = $seed;
}
/**
* Execute the job.
*/
public function handle(): void
{
// $response = Http::get($seed->uri);
dump($seed->uri);
$response = Http::get('https://diani.xyz/test.json');
$json = $response->json();
foreach($json['offers'] as $offer){
$property = Property::firstWhere('property_platform_id', $offer['id']);
if($property && $property->check_data === implode(',', $offer['geoLocation'])){
$property->last_found = now();
$property->save();
}else if($property && $property->check_data !== implode(',', $offer['geoLocation'])){
dump('error');
}else{
Property::create([
'property_platform_id' => $offer['id'],
'seed_id' => $seed->id,
'check_data' => implode(',', $offer['geoLocation']),
'last_found' => now()
]);
}
}
}
}