Flatisfy is your new companion to ease your search of a new housing :)

module.py 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # -*- coding: utf-8 -*-
  2. # Copyright(C) 2014 Bezleputh
  3. #
  4. # This file is part of a weboob module.
  5. #
  6. # This weboob module is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Affero General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This weboob module is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Affero General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Affero General Public License
  17. # along with this weboob module. If not, see <http://www.gnu.org/licenses/>.
  18. from weboob.tools.backend import Module
  19. from weboob.capabilities.housing import (CapHousing, Housing, HousingPhoto,
  20. ADVERT_TYPES)
  21. from weboob.capabilities.base import UserError
  22. from .browser import LogicimmoBrowser
  23. __all__ = ['LogicimmoModule']
  24. class LogicImmoCitiesError(UserError):
  25. """
  26. Raised when more than 3 cities are selected
  27. """
  28. def __init__(self, msg='You cannot select more than three cities'):
  29. UserError.__init__(self, msg)
  30. class LogicimmoModule(Module, CapHousing):
  31. NAME = 'logicimmo'
  32. DESCRIPTION = u'logicimmo website'
  33. MAINTAINER = u'Bezleputh'
  34. EMAIL = 'carton_ben@yahoo.fr'
  35. LICENSE = 'AGPLv3+'
  36. VERSION = '2.1'
  37. BROWSER = LogicimmoBrowser
  38. def get_housing(self, housing):
  39. if isinstance(housing, Housing):
  40. id = housing.id
  41. else:
  42. id = housing
  43. housing = None
  44. housing = self.browser.get_housing(id, housing)
  45. return housing
  46. def search_city(self, pattern):
  47. return self.browser.get_cities(pattern)
  48. def search_housings(self, query):
  49. if(len(query.advert_types) == 1 and
  50. query.advert_types[0] == ADVERT_TYPES.PERSONAL):
  51. # Logic-immo is pro only
  52. return list()
  53. cities_names = ['%s' % c.name.replace(' ', '-') for c in query.cities if c.backend == self.name]
  54. cities_ids = ['%s' % c.id for c in query.cities if c.backend == self.name]
  55. if len(cities_names) == 0:
  56. return list()
  57. if len(cities_names) > 3:
  58. raise LogicImmoCitiesError()
  59. cities = ','.join(cities_names + cities_ids)
  60. return self.browser.search_housings(query.type, cities.lower(), query.nb_rooms,
  61. query.area_min, query.area_max,
  62. query.cost_min, query.cost_max,
  63. query.house_types)
  64. def fill_housing(self, housing, fields):
  65. if 'phone' in fields:
  66. housing.phone = self.browser.get_phone(housing.id)
  67. fields.remove('phone')
  68. if len(fields) > 0:
  69. self.browser.get_housing(housing.id, housing)
  70. return housing
  71. def fill_photo(self, photo, fields):
  72. if 'data' in fields and photo.url and not photo.data:
  73. photo.data = self.browser.open(photo.url).content
  74. return photo
  75. OBJECTS = {Housing: fill_housing,
  76. HousingPhoto: fill_photo,
  77. }