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

59 lines
1.8 KiB
PHP
Raw Normal View History

2024-03-23 10:05:14 +01:00
<?php
namespace App\Jobs;
use App\Models\Seed;
2024-04-13 00:34:40 +02:00
use App\Models\Exception;
2024-03-23 10:05:14 +01:00
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;
2024-04-13 00:34:40 +02:00
use Illuminate\Support\Facades\Http;
2024-03-23 10:05:14 +01:00
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){
2024-04-13 00:34:40 +02:00
// Guessed ID to identify property on scraped platform
2024-03-23 10:05:14 +01:00
$property = Property::firstWhere('property_platform_id', $offer['id']);
2024-04-13 00:34:40 +02:00
// check if geoLocation hast the same values as the last time at crawltime
2024-03-23 10:05:14 +01:00
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()
]);
}
}
}
}