🎉 Hello world

This commit is contained in:
2020-07-23 12:26:10 +02:00
commit 2de65bb4aa
113 changed files with 69672 additions and 0 deletions

51
app/Parser/LBC.php Normal file
View File

@@ -0,0 +1,51 @@
<?php
namespace App\Parser;
use Absmoca\Leboncoin;
use App\ParsedHome;
use App\Parser;
class LBC extends Parser
{
public function __construct($url)
{
parent::__construct($url);
}
/**
* @return \App\ParsedHome
*/
public function parse(): ParsedHome
{
$idAnnonce = (int) $this->getIdAnnonceFromUrl($this->url);
$lbc = new Leboncoin();
$annonce = $lbc->getAnnonce($idAnnonce);
$parsedHome = new ParsedHome();
$parsedHome->title = $annonce->getName();
$parsedHome->price = $annonce->getPrice();
$attributes = $annonce->getAttributes();
$parsedHome->surface = $attributes[1]->value;
$parsedHome->rooms = $attributes[2]->value;
$parsedHome->energy = strtoupper($attributes[3]->value);
$parsedHome->ges = strtoupper($attributes[4]->value);
$parsedHome->description = $annonce->getDescription();
$parsedHome->pictures = $annonce->getImages();
$location = $annonce->getLocation();
$parsedHome->city = $location['city'];
$parsedHome->map = ['lat' => $location['lat'], 'lng' => $location['lng']];
return $parsedHome;
}
/**
* @param $url
*
* @return string
*/
private function getIdAnnonceFromUrl($url)
{
// ex : https://www.leboncoin.fr/ventes_immobilieres/1813996383.htm/
return collect(explode('.', collect(array_filter(explode('/', $url)))->last()))->first();
}
}

61
app/Parser/Pap.php Normal file
View File

@@ -0,0 +1,61 @@
<?php
namespace App\Parser;
use App\ParsedHome;
use App\Parser;
class Pap extends Parser
{
/**
* @inheritDoc
*/
public function parse(): ParsedHome
{
$idAnnonce = $this->getIdAnnonceFromUrl($this->url);
$url = sprintf('https://ws.pap.fr/immobilier/annonces/%s', (int)$idAnnonce);
$request = $this->client->get(
$url,
[
'headers' => [
'X-Device-Gsf' => '36049adaf18ade77',
'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();
$parsedHome->city = $annonce['_embedded']['place'][0]['title'];
//ex: Vente maison 110 m² Tréguier (22220)
$parsedHome->title = sprintf('%s %s %s m² %s',
ucfirst($annonce['produit']),
$annonce['typebien'],
$annonce['surface'],
$parsedHome->city
);
$parsedHome->price = $annonce['prix'];
$parsedHome->surface = $annonce['surface'];
$parsedHome->rooms = $annonce['nb_pieces'];
$parsedHome->energy = $annonce['classe_energie'];
$parsedHome->description = $annonce['texte'];
$parsedHome->pictures = collect(
$annonce['_embedded']['photo']
)->map(static function($photo) {
return $photo['_links']['self']['href'];
});
$location = $annonce['marker'];
$parsedHome->map = ['lat' => $location['lat'], 'lng' => $location['lng']];
return $parsedHome;
}
function getIdAnnonceFromUrl($url)
{
//ex: https://www.pap.fr/annonces/maison-treguier-22220-r432301732
return substr(collect(explode('-', collect(array_filter(explode('/', $url)))->last()))->last(), 1);
}
}

34
app/Parser/SeLoger.php Normal file
View File

@@ -0,0 +1,34 @@
<?php
namespace App\Parser;
use App\ParsedHome;
use App\Parser;
class SeLoger extends Parser
{
protected $params = [
'idtt' => 1,
'idtypebien' => '1,2',
'getDtCreationMax' => 1,
];
/**
* @inheritDoc
*/
public function parse(): ParsedHome
{
$idAnnonce = $this->getIdAnnonceFromUrl($this->url);
var_dump($idAnnonce);
$payload = $this->params + ['noAudiotel' => 1, 'idAnnonce' => $idAnnonce];
$request = $this->client->request('GET', "http://ws.seloger.com/annonceDetail_4.0.xml", $payload);
var_dump($request);
exit;
}
private function getIdAnnonceFromUrl($url)
{
// ex : https://www.seloger.com/annonces/achat/maison/franconville-95/vieux-marche-mare-des-noues/159100953.htm
return collect(explode('.', collect(explode('/', $url))->last()))->first();
}
}