ParuVenduImmoBridge.php 2.9 KB

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