2024-03-23 10:05:14 +01:00
|
|
|
<?php
|
|
|
|
namespace App\Scraper;
|
|
|
|
|
|
|
|
use App\Models\Seed;
|
|
|
|
use App\Models\Property;
|
|
|
|
use App\Models\Occupancy;
|
2024-04-09 22:36:40 +02:00
|
|
|
use App\Models\Exception;
|
|
|
|
use App\Jobs\ScrapeProperty;
|
|
|
|
use App\Jobs\ScrapePropertyData;
|
2024-03-23 10:05:14 +01:00
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
|
|
|
|
class Edomizil{
|
|
|
|
|
2024-04-09 22:36:40 +02:00
|
|
|
public static function getAllSeeds()
|
|
|
|
{
|
|
|
|
// get all properties from model in random order.
|
|
|
|
return Seed::select('id','uri')->inRandomOrder()->get();
|
|
|
|
}
|
2024-03-23 10:05:14 +01:00
|
|
|
|
2024-04-09 22:36:40 +02:00
|
|
|
public static function getAllProperties()
|
|
|
|
{
|
|
|
|
// get all properties from model in random order.
|
|
|
|
return Property::select('id','property_platform_id')->inRandomOrder()->get();
|
|
|
|
}
|
2024-03-23 10:05:14 +01:00
|
|
|
|
2024-04-09 22:36:40 +02:00
|
|
|
public static function dispatchPropertyJobs()
|
|
|
|
{
|
|
|
|
$seeds = self::getAllSeeds();
|
|
|
|
foreach($seeds as $seed){
|
|
|
|
ScrapeProperty::dispatch($seed->uri);
|
|
|
|
}
|
|
|
|
}
|
2024-03-23 10:05:14 +01:00
|
|
|
|
2024-04-09 22:36:40 +02:00
|
|
|
public static function dispatchPropertyDataJobs()
|
|
|
|
{
|
|
|
|
$properties = self::getAllProperties();
|
|
|
|
foreach($properties as $property){
|
|
|
|
dump($property->property_platform_id);
|
|
|
|
// ScrapePropertyData::dispatch($property->property_platform_id);
|
|
|
|
}
|
|
|
|
}
|
2024-03-23 10:05:14 +01:00
|
|
|
|
2024-04-09 22:36:40 +02:00
|
|
|
public static function scrapeProperty($uri)
|
|
|
|
{
|
|
|
|
//$response = Http::get($seed->uri);
|
|
|
|
$response = Http::get('https://diani.xyz/test_2.json');
|
|
|
|
$json = $response->json();
|
|
|
|
|
|
|
|
foreach($json['offers'] as $offer){
|
|
|
|
|
|
|
|
$property = Property::firstWhere('property_platform_id', $offer['id']);
|
|
|
|
$geoLocation = implode(',', $offer['geoLocation']);
|
|
|
|
|
|
|
|
if($property){
|
|
|
|
$property->last_found = now();
|
|
|
|
$property->save();
|
|
|
|
if($property->check_data !== $geoLocation){
|
|
|
|
Exception::create([
|
|
|
|
'exception' => 'geoLocation was different: '.$geoLocation,
|
|
|
|
'entity_type' => 'property',
|
|
|
|
'entity_id' => $offer['id']
|
2024-03-23 10:05:14 +01:00
|
|
|
]);
|
|
|
|
}
|
2024-04-09 22:36:40 +02:00
|
|
|
}else{
|
|
|
|
Property::create([
|
|
|
|
'property_platform_id' => $offer['id'],
|
|
|
|
'seed_id' => $seed->id,
|
|
|
|
'check_data' => $geoLocation,
|
|
|
|
'last_found' => now()
|
|
|
|
]);
|
2024-03-23 10:05:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-09 22:36:40 +02:00
|
|
|
public static function scrapeOccupancy($propertyId){
|
|
|
|
/*
|
|
|
|
$calendar = Http::get('https://www.e-domizil.ch/api/v2/calendar/'.$propertyId, [
|
|
|
|
'year' => date("Y"),
|
|
|
|
'month' => date("m")
|
|
|
|
]);
|
|
|
|
$data_cal = $calendar->json();
|
|
|
|
|
|
|
|
$price = Http::get('https://www.e-domizil.ch/booking/checkout/priceDetails/'.$propertyId);
|
|
|
|
$data_price = $price->json();
|
|
|
|
|
|
|
|
$offer = Http::get('https://www.e-domizil.ch/rental/offer/'.$propertyId);
|
|
|
|
$data_offer = $offer->json();
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
$data = $response->json();
|
|
|
|
Occupancy::create([
|
|
|
|
'property_id' => $property->id,
|
|
|
|
'occupancy' => json_encode($data['content']['days']),
|
|
|
|
'header' => json_encode($response->headers())
|
|
|
|
]);
|
|
|
|
*/
|
2024-03-23 10:05:14 +01:00
|
|
|
|
2024-04-09 22:36:40 +02:00
|
|
|
|
2024-03-23 10:05:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|