ParuVenduImmoBridge.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 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('name'=>'department numbers or postal codes, comma-separated')
  22. ));
  23. public function collectData()
  24. {
  25. $html = getSimpleHTMLDOM($this->getURI())
  26. or returnServerError('Could not request paruvendu.');
  27. foreach($html->find('div.annonce a') as $element) {
  28. if (!$element->title) {
  29. continue;
  30. }
  31. $img ='';
  32. foreach($element->find('span.img img') as $img) {
  33. if ($img->original) {
  34. $img = '<img src="'.$img->original.'" />';
  35. }
  36. }
  37. $desc = $element->find('span.desc')[0]->innertext;
  38. $desc = str_replace("voir l'annonce", '', $desc);
  39. $price = $element->find('span.price')[0]->innertext;
  40. list($href) = explode('#', $element->href);
  41. $item = array();
  42. $item['uri'] = self::URI.$href;
  43. $item['title'] = $element->title;
  44. $item['content'] = $img.$desc.$price;
  45. $this->items[] = $item;
  46. }
  47. }
  48. public function getURI(){
  49. $appartment = '&tbApp=1&tbDup=1&tbChb=1&tbLof=1&tbAtl=1&tbPla=1';
  50. $maison = '&tbMai=1&tbVil=1&tbCha=1&tbPro=1&tbHot=1&tbMou=1&tbFer=1';
  51. $link = self::URI.'/immobilier/annonceimmofo/liste/listeAnnonces?tt=1'.$appartment.$maison;
  52. if ($this->getInput('minarea')) {
  53. $link .= '&sur0='.urlencode($this->getInput('minarea'));
  54. }
  55. if ($this->getInput('maxprice')) {
  56. $link .= '&px1='.urlencode($this->getInput('maxprice'));
  57. }
  58. if ($this->getInput('pa')) {
  59. $link .= '&pa='.urlencode($this->getInput('pa'));
  60. }
  61. if ($this->getInput('lo')) {
  62. $link .= '&lo='.urlencode($this->getInput('lo'));
  63. }
  64. return $link;
  65. }
  66. public function getName(){
  67. $request='';
  68. $minarea=$this->getInput('minarea');
  69. if(!empty($minarea)){
  70. $request .= ' '.$minarea.' m2';
  71. }
  72. $location=$this->getInput('lo');
  73. if(!empty($location)){
  74. $request .= ' In: '.$location;
  75. }
  76. return 'Paru Vendu Immobilier'.$request;
  77. }
  78. public function getCacheDuration(){
  79. return 10800; // 3 hours
  80. }
  81. }