ParuVenduImmoBridge.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. class ParuVenduImmoBridge extends BridgeAbstract
  3. {
  4. const MAINTAINER = "polo2ro";
  5. const NAME = "Paru Vendu Immobilier";
  6. const URI = "http://www.paruvendu.fr";
  7. const CACHE_TIMEOUT = 10800; // 3h
  8. const DESCRIPTION = "Returns the ads from the first page of search result.";
  9. const PARAMETERS = array( array(
  10. 'minarea'=>array(
  11. 'name'=>'Minimal surface m²',
  12. 'type'=>'number'
  13. ),
  14. 'maxprice'=>array(
  15. 'name'=>'Max price',
  16. 'type'=>'number'
  17. ),
  18. 'pa'=>array(
  19. 'name'=>'Country code',
  20. 'exampleValue'=>'FR'
  21. ),
  22. 'lo'=>array('name'=>'department numbers or postal codes, comma-separated')
  23. ));
  24. public function collectData()
  25. {
  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.'/immobilier/annonceimmofo/liste/listeAnnonces?tt=1'.$appartment.$maison;
  53. if ($this->getInput('minarea')) {
  54. $link .= '&sur0='.urlencode($this->getInput('minarea'));
  55. }
  56. if ($this->getInput('maxprice')) {
  57. $link .= '&px1='.urlencode($this->getInput('maxprice'));
  58. }
  59. if ($this->getInput('pa')) {
  60. $link .= '&pa='.urlencode($this->getInput('pa'));
  61. }
  62. if ($this->getInput('lo')) {
  63. $link .= '&lo='.urlencode($this->getInput('lo'));
  64. }
  65. return $link;
  66. }
  67. public function getName(){
  68. $request='';
  69. $minarea=$this->getInput('minarea');
  70. if(!empty($minarea)){
  71. $request .= ' '.$minarea.' m2';
  72. }
  73. $location=$this->getInput('lo');
  74. if(!empty($location)){
  75. $request .= ' In: '.$location;
  76. }
  77. return 'Paru Vendu Immobilier'.$request;
  78. }
  79. }