59 lines
1.8 KiB
PHP
59 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Models\Seed;
|
|
use App\Models\Exception;
|
|
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;
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
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);
|
|
$response = Http::get('https://diani.xyz/test.json');
|
|
$json = $response->json();
|
|
|
|
foreach($json['offers'] as $offer){
|
|
|
|
// Guessed ID to identify property on scraped platform
|
|
$property = Property::firstWhere('property_platform_id', $offer['id']);
|
|
|
|
// check if geoLocation hast the same values as the last time at crawltime
|
|
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()
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
}
|