rss-bridge/bridges/ParuVenduImmoBridge.php

98 lines
2.8 KiB
PHP
Raw Normal View History

2015-02-01 15:03:39 +01:00
<?php
2015-02-01 15:03:39 +01:00
class ParuVenduImmoBridge extends BridgeAbstract
{
2015-02-01 15:15:30 +01:00
private $request = '';
2015-02-01 15:03:39 +01:00
public function loadMetadatas() {
$this->maintainer = "polo2ro";
$this->name = "Paru Vendu Immobilier";
$this->uri = "http://www.paruvendu.fr";
$this->description = "Returns the ads from the first page of search result.";
$this->parameters[] = array(
'minarea'=>array(
'name'=>'Minimal surface m²',
'type'=>'number'
),
'maxprice'=>array(
'name'=>'Max price',
'type'=>'number'
),
'pa'=>array(
'name'=>'Country code',
'exampleValue'=>'FR'
),
'lo'=>array('name'=>'department numbers or postal codes, comma-separated')
);
}
public function collectData()
2015-02-01 15:03:39 +01:00
{
$html = '';
$num = 20;
2015-02-01 19:20:13 +01:00
$appartment = '&tbApp=1&tbDup=1&tbChb=1&tbLof=1&tbAtl=1&tbPla=1';
$maison = '&tbMai=1&tbVil=1&tbCha=1&tbPro=1&tbHot=1&tbMou=1&tbFer=1';
$link = $this->uri.'/immobilier/annonceimmofo/liste/listeAnnonces?tt=1'.$appartment.$maison;
if (isset($param['minarea']['value'])) {
$this->request .= ' '.$param['minarea']['value'].' m2';
$link .= '&sur0='.urlencode($param['minarea']['value']);
2015-02-01 15:03:39 +01:00
}
if (isset($param['maxprice']['value'])) {
$link .= '&px1='.urlencode($param['maxprice']['value']);
2015-02-01 15:03:39 +01:00
}
if (isset($param['pa']['value'])) {
$link .= '&pa='.urlencode($param['pa']['value']);
2015-02-01 15:03:39 +01:00
}
if (isset($param['lo']['value'])) {
$this->request .= ' In: '.$param['lo']['value'];
$link .= '&lo='.urlencode($param['lo']['value']);
2015-02-01 15:03:39 +01:00
}
$html = $this->getSimpleHTMLDOM($link) or $this->returnServerError('Could not request paruvendu.');
2015-02-01 15:03:39 +01:00
foreach($html->find('div.annonce a') as $element) {
2015-02-01 18:03:15 +01:00
if (!$element->title) {
continue;
}
2015-02-01 15:03:39 +01:00
$img ='';
foreach($element->find('span.img img') as $img) {
if ($img->original) {
$img = '<img src="'.$img->original.'" />';
}
}
2015-02-01 15:03:39 +01:00
$desc = $element->find('span.desc')[0]->innertext;
$desc = str_replace("voir l'annonce", '', $desc);
2015-02-01 15:03:39 +01:00
$price = $element->find('span.price')[0]->innertext;
list($href) = explode('#', $element->href);
$item = array();
$item['uri'] = $this->uri.$href;
$item['title'] = $element->title;
$item['content'] = $img.$desc.$price;
2015-02-01 15:03:39 +01:00
$this->items[] = $item;
}
}
public function getName(){
2015-02-01 15:15:30 +01:00
return 'Paru Vendu Immobilier'.$this->request;
2015-02-01 15:03:39 +01:00
}
public function getCacheDuration(){
2015-02-01 15:04:59 +01:00
return 10800; // 3 hours
2015-02-01 15:03:39 +01:00
}
}