ParuVenduImmoBridge.php 2.4 KB

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