module.py 2.24 KB
Newer Older
1 2 3 4
# -*- coding: utf-8 -*-

# Copyright(C) 2015      Bezleputh
#
5
# This file is part of a weboob module.
6
#
7
# This weboob module is free software: you can redistribute it and/or modify
8 9 10 11
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
12
# This weboob module is distributed in the hope that it will be useful,
13 14 15 16 17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
18
# along with this weboob module. If not, see <http://www.gnu.org/licenses/>.
19 20 21


from weboob.tools.backend import Module
Phyks (Lucas Verney)'s avatar
Phyks (Lucas Verney) committed
22
from weboob.capabilities.housing import (CapHousing, HousingPhoto,
23
                                         ADVERT_TYPES, Housing)
24 25 26 27 28 29 30 31 32 33 34 35 36

from .browser import EntreparticuliersBrowser


__all__ = ['EntreparticuliersModule']


class EntreparticuliersModule(Module, CapHousing):
    NAME = 'entreparticuliers'
    DESCRIPTION = u'entreparticuliers.com website'
    MAINTAINER = u'Bezleputh'
    EMAIL = 'carton_ben@yahoo.fr'
    LICENSE = 'AGPLv3+'
Romain Bignon's avatar
Romain Bignon committed
37
    VERSION = '1.6'
38 39 40 41 42 43 44

    BROWSER = EntreparticuliersBrowser

    def search_city(self, pattern):
        return self.browser.search_city(pattern)

    def search_housings(self, query):
45
        if(len(query.advert_types) == 1 and
46
           query.advert_types[0] == ADVERT_TYPES.PROFESSIONAL):
47 48 49
            # Entreparticuliers is personal only
            return list()

50
        cities = [c for c in query.cities if c.backend == self.name]
51
        if len(cities) == 0:
52
            return []
53

54
        return self.browser.search_housings(query, cities)
55 56 57 58 59 60 61 62 63

    def get_housing(self, _id):
        return self.browser.get_housing(_id)

    def fill_photo(self, photo, fields):
        if 'data' in fields and photo.url and not photo.data:
            photo.data = self.browser.open(photo.url).content
        return photo

64 65 66 67 68 69 70
    def fill_housing(self, housing, fields):
        if len(fields) > 0:
            self.browser.get_housing(housing.id, housing)

        return housing

    OBJECTS = {HousingPhoto: fill_photo, Housing: fill_housing}