ParuVenduImmoBridge.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. class ParuVenduImmoBridge extends BridgeAbstract
  3. {
  4. private $request = '';
  5. public function loadMetadatas() {
  6. $this->maintainer = "polo2ro";
  7. $this->name = "Paru Vendu Immobilier";
  8. $this->uri = "http://www.paruvendu.fr";
  9. $this->description = "Returns the ads from the first page of search result.";
  10. $this->parameters[] = array(
  11. 'minarea'=>array(
  12. 'name'=>'Minimal surface m²',
  13. 'type'=>'number'
  14. ),
  15. 'maxprice'=>array(
  16. 'name'=>'Max price',
  17. 'type'=>'number'
  18. ),
  19. 'pa'=>array(
  20. 'name'=>'Country code',
  21. 'exampleValue'=>'FR'
  22. ),
  23. 'lo'=>array('name'=>'department numbers or postal codes, comma-separated')
  24. );
  25. }
  26. public function collectData(array $param)
  27. {
  28. $html = '';
  29. $num = 20;
  30. $appartment = '&tbApp=1&tbDup=1&tbChb=1&tbLof=1&tbAtl=1&tbPla=1';
  31. $maison = '&tbMai=1&tbVil=1&tbCha=1&tbPro=1&tbHot=1&tbMou=1&tbFer=1';
  32. $link = $this->uri.'/immobilier/annonceimmofo/liste/listeAnnonces?tt=1'.$appartment.$maison;
  33. if (isset($param['minarea'])) {
  34. $this->request .= ' '.$param['minarea'].' m2';
  35. $link .= '&sur0='.urlencode($param['minarea']);
  36. }
  37. if (isset($param['maxprice'])) {
  38. $link .= '&px1='.urlencode($param['maxprice']);
  39. }
  40. if (isset($param['pa'])) {
  41. $link .= '&pa='.urlencode($param['pa']);
  42. }
  43. if (isset($param['lo'])) {
  44. $this->request .= ' In: '.$param['lo'];
  45. $link .= '&lo='.urlencode($param['lo']);
  46. }
  47. $html = $this->getSimpleHTMLDOM($link) or $this->returnServerError('Could not request paruvendu.');
  48. foreach($html->find('div.annonce a') as $element) {
  49. if (!$element->title) {
  50. continue;
  51. }
  52. $img ='';
  53. foreach($element->find('span.img img') as $img) {
  54. if ($img->original) {
  55. $img = '<img src="'.$img->original.'" />';
  56. }
  57. }
  58. $desc = $element->find('span.desc')[0]->innertext;
  59. $desc = str_replace("voir l'annonce", '', $desc);
  60. $price = $element->find('span.price')[0]->innertext;
  61. list($href) = explode('#', $element->href);
  62. $item = array();
  63. $item['uri'] = $this->uri.$href;
  64. $item['title'] = $element->title;
  65. $item['content'] = $img.$desc.$price;
  66. $this->items[] = $item;
  67. }
  68. }
  69. public function getName(){
  70. return 'Paru Vendu Immobilier'.$this->request;
  71. }
  72. public function getCacheDuration(){
  73. return 10800; // 3 hours
  74. }
  75. }