From 83ecfa4593df77433e51291e368ab0bf867088c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gi=C3=B2?= Date: Sat, 13 Apr 2024 00:54:08 +0200 Subject: [PATCH] Cleanup & beginning of custom commands. --- .../app/Console/Commands/scrapeProperty.php | 30 ++++++++++ .../Console/Commands/scrapePropertyDate.php | 30 ++++++++++ scraper/app/Jobs/ScrapeProperyData.php | 8 ++- scraper/app/Jobs/scrapeProperties.php | 58 ------------------- scraper/app/Scraper/Edomizil.php | 22 +++---- scraper/routes/web.php | 9 --- 6 files changed, 76 insertions(+), 81 deletions(-) create mode 100644 scraper/app/Console/Commands/scrapeProperty.php create mode 100644 scraper/app/Console/Commands/scrapePropertyDate.php delete mode 100644 scraper/app/Jobs/scrapeProperties.php diff --git a/scraper/app/Console/Commands/scrapeProperty.php b/scraper/app/Console/Commands/scrapeProperty.php new file mode 100644 index 0000000..2825cda --- /dev/null +++ b/scraper/app/Console/Commands/scrapeProperty.php @@ -0,0 +1,30 @@ +property = $property; } /** @@ -25,6 +27,6 @@ class ScrapeProperyData implements ShouldQueue */ public function handle(): void { - // + Edomizil::scrapePropertyData($this->property); } } diff --git a/scraper/app/Jobs/scrapeProperties.php b/scraper/app/Jobs/scrapeProperties.php deleted file mode 100644 index dc30f8e..0000000 --- a/scraper/app/Jobs/scrapeProperties.php +++ /dev/null @@ -1,58 +0,0 @@ -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() - ]); - } - } - } -} diff --git a/scraper/app/Scraper/Edomizil.php b/scraper/app/Scraper/Edomizil.php index f583abe..4791adb 100644 --- a/scraper/app/Scraper/Edomizil.php +++ b/scraper/app/Scraper/Edomizil.php @@ -53,7 +53,7 @@ class Edomizil{ { $properties = self::getAllProperties(); foreach($properties as $property){ - ScrapePropertyData::dispatch($property->property_platform_id); + ScrapePropertyData::dispatch($property); } } @@ -96,42 +96,42 @@ class Edomizil{ } } - public static function scrapePropertyData($propertyId){ + public static function scrapePropertyData($property){ // scrape offer details such as name etc. - $offer = Http::get('https://www.e-domizil.ch/rental/offer/'.$propertyId); + $offer = Http::get('https://www.e-domizil.ch/rental/offer/'.$property->property_platform_id); if($offer->successful()){ Extraction::create([ - 'property_id' => $propertyId, + 'property_id' => $property->id, 'type' => 'offer', 'body' => $offer->body(), 'header' => json_encode($offer->headers()) ]); }else{ - self::saveHttpException($offer,'offer',$propertyId); + self::saveHttpException($offer,'offer',$property->id); } // scrape price of property - $price = Http::get('https://www.e-domizil.ch/booking/checkout/priceDetails/'.$propertyId); + $price = Http::get('https://www.e-domizil.ch/booking/checkout/priceDetails/'.$property->property_platform_id); if($price->successful()){ Extraction::create([ - 'property_id' => $propertyId, + 'property_id' => $property->id, 'type' => 'price', 'body' => $price->body(), 'header' => json_encode($price->headers()) ]); }else{ - self::saveHttpException($price,'price',$propertyId); + self::saveHttpException($price,'price',$property->id); } // scrape calendar which contains occupancies - $calendar = Http::get('https://www.e-domizil.ch/api/v2/calendar/'.$propertyId, [ + $calendar = Http::get('https://www.e-domizil.ch/api/v2/calendar/'.$property->property_platform_id, [ 'year' => date("Y"), 'month' => date("m") ]); @@ -139,14 +139,14 @@ class Edomizil{ if($calendar->successful()){ Extraction::create([ - 'property_id' => $propertyId, + 'property_id' => $property->id, 'type' => 'calendar', 'body' => $calendar->body(), 'header' => json_encode($calendar->headers()) ]); }else{ - self::saveHttpException($calendar,'price',$propertyId); + self::saveHttpException($calendar,'price',$property->id); } } diff --git a/scraper/routes/web.php b/scraper/routes/web.php index 5e143da..8802d30 100644 --- a/scraper/routes/web.php +++ b/scraper/routes/web.php @@ -7,12 +7,3 @@ Route::get('/', function () { return view('index'); }); -Route::get('/properties', function () { - Edomizil::dispatchPropertyJobs(); -}); - -Route::get('/propertydata', function () { - Edomizil::scrapePropertyData(1); - //Edomizil::dispatchPropertyDataJobs(); -}); -