Ajoute le Parser Immobilier Notaires

This commit is contained in:
Clement 2020-09-11 11:32:15 +02:00
parent ff742cd62c
commit 507960182f
3 changed files with 75 additions and 2 deletions

View File

@ -0,0 +1,71 @@
<?php
namespace App\Parser;
use App\ParsedHome;
use App\Parser;
use Symfony\Component\DomCrawler\Crawler;
class ImmobilierNotaires extends Parser
{
/**
* @inheritDoc
*/
public function parse(): ParsedHome
{
$idAnnonce = $this->getIdAnnonceFromUrl($this->url);
$url = sprintf('https://www.immobilier.notaires.fr/pub-services/inotr-www-annonces/v1/annonces/%s', (int)$idAnnonce);
$request = $this->client->get(
$url,
[
'headers' => [
'Referer' => $this->url,
'User-Agent' => 'Dalvik/2.1.0 (Linux; U; Android 6.0.1; D5803 Build/MOB30M.Z1)',
'Connection' => 'Keep-Alive',
'Accept-Encoding' => 'gzip'
],
]
);
$annonce = json_decode($request->getBody()->getContents(), true);
$parsedHome = new ParsedHome();
$transaction = $annonce[strtolower($annonce['typeTransaction'])];
$images = $transaction['multimedias'];
$parsedHome->pictures = [];
foreach ($images as $image) {
$parsedHome->pictures[] = $image['vga'];
}
$parsedHome->description = $transaction['descriptions'][0]['descLongue'];
if (array_key_exists('prixTotal', $transaction)) {
$parsedHome->price = $transaction['prixTotal'];
} elseif ($transaction['redevableEmoluments'] === 'ACQUEREUR') {
$parsedHome->price = $transaction['prix'] + $transaction['emoluments'];
} else {
$parsedHome->price = $transaction['prix'];
}
$bien = $annonce['bien'];
$maison = $bien['maison'];
$parsedHome->city = $maison['communeNom'];
$parsedHome->surface = $maison['surfaceHabitable'];
$parsedHome->garden_surface = $maison['surfaceTerrain'] ?? null;
$parsedHome->rooms = $maison['nbPieces'];
$parsedHome->title = $transaction['descriptions'][0]['descCourte'];
$parsedHome->energy = $maison['consommationClasse'] === 'Y' ? null : $maison['consommationClasse'];
$parsedHome->ges = $maison['emissionGesClasse'] === 'Y' ? null : $maison['emissionGesClasse'];
if (array_key_exists('coordonneesExactesW84', $maison)) {
$parsedHome->map = [
'lat' => $maison['coordonneesExactesW84']['coordonneeY'],
'lng' => $maison['coordonneesExactesW84']['coordonneeX']
];
}
return $parsedHome;
}
private function getIdAnnonceFromUrl($url)
{
// ex: https://www.immobilier.notaires.fr/fr/annonce-immo/immo-interactif/maison/rognac-13/1263723
$url = parse_url($url, PHP_URL_PATH);
return collect(explode('/', $url))->last();
}
}

View File

@ -1,5 +1,6 @@
<?php
use App\Parser\ImmobilierNotaires;
use App\Parser\LannionImmo;
use App\Parser\LBC;
use App\Parser\OuestFrance;
@ -12,6 +13,7 @@ return [
'seloger.com' => SeLoger::class,
'pap.fr' => Pap::class,
'ouestfrance-immo.com' => OuestFrance::class,
'lannion.immo' => LannionImmo::class
'lannion.immo' => LannionImmo::class,
'immobilier.notaires.fr'=> ImmobilierNotaires::class
],
];