Neue commands.
This commit is contained in:
		
							parent
							
								
									42cc96a14a
								
							
						
					
					
						commit
						d2f1c82098
					
				@ -29,10 +29,12 @@ class scrapeProperty extends Command
 | 
			
		||||
 | 
			
		||||
        $seeds = Edomizil::getAllSeeds();
 | 
			
		||||
        foreach($seeds as $seed){
 | 
			
		||||
            Edomizil::ScrapeProperty($seed);
 | 
			
		||||
            $this->info('Scraping '.$seed);
 | 
			
		||||
            $scraper = Edomizil::ScrapeProperty($seed);
 | 
			
		||||
            $this->info($scraper.' properties were found.');
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $this->info('Scraping was successfull.');
 | 
			
		||||
        $this->info('Finished scraping.');
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -13,7 +13,7 @@ class scrapePropertyDate extends Command
 | 
			
		||||
     *
 | 
			
		||||
     * @var string
 | 
			
		||||
     */
 | 
			
		||||
    protected $signature = 'scrape:propertydata {propertyId?}';
 | 
			
		||||
    protected $signature = 'scrape:propertydata {propertyId?} {--seed=}';
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The console command description.
 | 
			
		||||
@ -28,15 +28,23 @@ class scrapePropertyDate extends Command
 | 
			
		||||
    public function handle()
 | 
			
		||||
    {
 | 
			
		||||
        $propertyId = $this->argument('propertyId');
 | 
			
		||||
        $seed = $this->option('seed');
 | 
			
		||||
 | 
			
		||||
        if($propertyId && is_numeric($propertyId)){
 | 
			
		||||
            $property = Property::select('id','property_platform_id')->where('id', 'like', $propertyId)->get();
 | 
			
		||||
        }else{
 | 
			
		||||
            $property = Property::select('id','property_platform_id')->inRandomOrder()->take(1)->get();        
 | 
			
		||||
        if($seed){
 | 
			
		||||
 | 
			
		||||
            $property = Property::select('id','property_platform_id')->where('seed_id', $seed)->inRandomOrder()->take(1)->get(); 
 | 
			
		||||
 | 
			
		||||
        } else {
 | 
			
		||||
 | 
			
		||||
            if($propertyId && is_numeric($propertyId)){
 | 
			
		||||
                $property = Property::select('id','property_platform_id')->where('id', 'like', $propertyId)->get();
 | 
			
		||||
            }else{
 | 
			
		||||
                $property = Property::select('id','property_platform_id')->inRandomOrder()->take(1)->get();        
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Edomizil::scrapePropertyData($property[0]);
 | 
			
		||||
        $this->info('Scraping for property '.$property[0]->property_platform_id.' has ended.');
 | 
			
		||||
        $data = Edomizil::scrapePropertyData($property[0]);
 | 
			
		||||
        $this->info('Scraping for property '.$property[0]->property_platform_id.' has ended. Here is the result: '.$data);
 | 
			
		||||
        
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -11,4 +11,9 @@ class Seed extends Model
 | 
			
		||||
    use HasFactory;
 | 
			
		||||
    protected $table = 'seeds';
 | 
			
		||||
 | 
			
		||||
    protected $fillable = [
 | 
			
		||||
        'region_id',
 | 
			
		||||
        'uri'
 | 
			
		||||
    ];
 | 
			
		||||
    
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -91,13 +91,20 @@ class Edomizil{
 | 
			
		||||
					]);
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			return count($json['offers']);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		}else{
 | 
			
		||||
			self::saveHttpException($response,'property', $seed->id);
 | 
			
		||||
			return 0;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static function scrapePropertyData($property){
 | 
			
		||||
 | 
			
		||||
		$result = [];
 | 
			
		||||
 | 
			
		||||
		// scrape offer details such as name etc.
 | 
			
		||||
		$offer = Http::get('https://www.e-domizil.ch/rental/offer/'.$property->property_platform_id);
 | 
			
		||||
		
 | 
			
		||||
@ -114,6 +121,8 @@ class Edomizil{
 | 
			
		||||
			self::saveHttpException($offer,'offer',$property->id);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$result['offer'] = $offer->body();
 | 
			
		||||
 | 
			
		||||
		// scrape price of property
 | 
			
		||||
		$price = Http::get('https://www.e-domizil.ch/booking/checkout/priceDetails/'.$property->property_platform_id);
 | 
			
		||||
 | 
			
		||||
@ -130,6 +139,8 @@ class Edomizil{
 | 
			
		||||
			self::saveHttpException($price,'price',$property->id);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$result['price'] = $price->body();
 | 
			
		||||
 | 
			
		||||
		// scrape calendar which contains occupancies
 | 
			
		||||
		$calendar = Http::get('https://www.e-domizil.ch/api/v2/calendar/'.$property->property_platform_id, [
 | 
			
		||||
			'year' => date("Y"),
 | 
			
		||||
@ -146,9 +157,13 @@ class Edomizil{
 | 
			
		||||
			]);
 | 
			
		||||
 | 
			
		||||
		}else{
 | 
			
		||||
			self::saveHttpException($calendar,'price',$property->id);
 | 
			
		||||
			self::saveHttpException($calendar,'calendar',$property->id);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$result['calendar'] = $calendar->body();
 | 
			
		||||
		
 | 
			
		||||
		return json_encode($result);
 | 
			
		||||
	
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -6,6 +6,8 @@
 | 
			
		||||
    "license": "MIT",
 | 
			
		||||
    "require": {
 | 
			
		||||
        "php": "^8.1",
 | 
			
		||||
        "filament/filament": "^3.2",
 | 
			
		||||
        "filament/infolists": "^3.2",
 | 
			
		||||
        "guzzlehttp/guzzle": "^7.2",
 | 
			
		||||
        "laravel/framework": "^10.10",
 | 
			
		||||
        "laravel/sanctum": "^3.3",
 | 
			
		||||
@ -35,7 +37,8 @@
 | 
			
		||||
    "scripts": {
 | 
			
		||||
        "post-autoload-dump": [
 | 
			
		||||
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
 | 
			
		||||
            "@php artisan package:discover --ansi"
 | 
			
		||||
            "@php artisan package:discover --ansi",
 | 
			
		||||
            "@php artisan filament:upgrade"
 | 
			
		||||
        ],
 | 
			
		||||
        "post-update-cmd": [
 | 
			
		||||
            "@php artisan vendor:publish --tag=laravel-assets --ansi --force"
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										2050
									
								
								scraper/composer.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										2050
									
								
								scraper/composer.lock
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@ -167,6 +167,7 @@ return [
 | 
			
		||||
        App\Providers\AuthServiceProvider::class,
 | 
			
		||||
        // App\Providers\BroadcastServiceProvider::class,
 | 
			
		||||
        App\Providers\EventServiceProvider::class,
 | 
			
		||||
        App\Providers\Filament\AdminPanelProvider::class,
 | 
			
		||||
        App\Providers\RouteServiceProvider::class,
 | 
			
		||||
    ])->toArray(),
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user