From 507960182f9321aa2614c8437dbdb711a67deba9 Mon Sep 17 00:00:00 2001 From: Clement Date: Fri, 11 Sep 2020 11:32:15 +0200 Subject: [PATCH] :sparkles: Ajoute le Parser Immobilier Notaires --- app/Parser/ImmobilierNotaires.php | 71 +++++++++++++++++++++++++++++++ app/Parser/LannionImmo.php | 2 +- config/parser.php | 4 +- 3 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 app/Parser/ImmobilierNotaires.php diff --git a/app/Parser/ImmobilierNotaires.php b/app/Parser/ImmobilierNotaires.php new file mode 100644 index 0000000..4bb72ec --- /dev/null +++ b/app/Parser/ImmobilierNotaires.php @@ -0,0 +1,71 @@ +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(); + } +} diff --git a/app/Parser/LannionImmo.php b/app/Parser/LannionImmo.php index a48b230..2c04769 100644 --- a/app/Parser/LannionImmo.php +++ b/app/Parser/LannionImmo.php @@ -55,7 +55,7 @@ class LannionImmo extends Parser if (strtolower($node->nodeName()) === 'a') { return $node->attr('href'); } - + if ($node->children('img')) { return $node->children('img')->attr('src'); } diff --git a/config/parser.php b/config/parser.php index c06aabd..ba8e13d 100644 --- a/config/parser.php +++ b/config/parser.php @@ -1,5 +1,6 @@ SeLoger::class, 'pap.fr' => Pap::class, 'ouestfrance-immo.com' => OuestFrance::class, - 'lannion.immo' => LannionImmo::class + 'lannion.immo' => LannionImmo::class, + 'immobilier.notaires.fr'=> ImmobilierNotaires::class ], ];