Skip to content
browser.py 2.88 KiB
Newer Older
Romain Bignon's avatar
Romain Bignon committed
# -*- coding: utf-8 -*-

# Copyright(C) 2012 Romain Bignon
#
# This file is part of a weboob module.
Romain Bignon's avatar
Romain Bignon committed
#
# This weboob module is free software: you can redistribute it and/or modify
Romain Bignon's avatar
Romain Bignon committed
# 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.
#
# This weboob module is distributed in the hope that it will be useful,
Romain Bignon's avatar
Romain Bignon committed
# 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
# along with this weboob module. If not, see <http://www.gnu.org/licenses/>.
Romain Bignon's avatar
Romain Bignon committed

from weboob.capabilities.housing import TypeNotSupported, POSTS_TYPES
from weboob.tools.compat import urlencode
Romain Bignon's avatar
Romain Bignon committed

Bezleputh's avatar
Bezleputh committed
from weboob.browser import PagesBrowser, URL
from .pages import SearchResultsPage, HousingPage, CitiesPage
from weboob.browser.profiles import Android
Romain Bignon's avatar
Romain Bignon committed

from .constants import TYPES, RET

Romain Bignon's avatar
Romain Bignon committed
__all__ = ['SeLogerBrowser']


Bezleputh's avatar
Bezleputh committed
class SeLogerBrowser(PagesBrowser):
    BASEURL = 'http://www.seloger.com'
    PROFILE = Android()
    cities = URL('https://autocomplete.svc.groupe-seloger.com/auto/complete/0/Ville/6\?text=(?P<pattern>.*)', CitiesPage)
Bezleputh's avatar
Bezleputh committed
    search = URL('http://ws.seloger.com/search.xml\?(?P<request>.*)', SearchResultsPage)
    housing = URL('http://ws.seloger.com/annonceDetail.xml\?idAnnonce=(?P<_id>\d+)&noAudiotel=(?P<noAudiotel>\d)',
                  HousingPage)
Romain Bignon's avatar
Romain Bignon committed

    def search_geo(self, pattern):
        return self.cities.open(pattern=pattern).iter_cities()
Romain Bignon's avatar
Romain Bignon committed

    def search_housings(self, type, cities, nb_rooms, area_min, area_max,
                        cost_min, cost_max, house_types, advert_types):
        if type not in TYPES:
Romain Bignon's avatar
Romain Bignon committed
        data = {'ci':            ','.join(cities),
                'idtt':          TYPES.get(type, 1),
Romain Bignon's avatar
Romain Bignon committed
                'org':           'advanced_search',
                'surfacemax':    area_max or '',
                'surfacemin':    area_min or '',
                'tri':           'd_dt_crea',
Bezleputh's avatar
Bezleputh committed
                }
Romain Bignon's avatar
Romain Bignon committed

        if type == POSTS_TYPES.SALE:
            data['pxmax'] = cost_max or ''
            data['pxmin'] = cost_min or ''
        else:
            data['px_loyermax'] = cost_max or ''
            data['px_loyermin'] = cost_min or ''

        if nb_rooms:
            data['nb_pieces'] = nb_rooms

Bezleputh's avatar
Bezleputh committed
        ret = []
        for house_type in house_types:
            if house_type in RET:
                ret.append(RET.get(house_type))
Romain Bignon's avatar
Romain Bignon committed

Bezleputh's avatar
Bezleputh committed
        if ret:
            data['idtypebien'] = ','.join(ret)
Romain Bignon's avatar
Romain Bignon committed

        return self.search.go(request=urlencode(data)).iter_housings(
            query_type=type, advert_types=advert_types
Romain Bignon's avatar
Romain Bignon committed

Bezleputh's avatar
Bezleputh committed
    def get_housing(self, _id, obj=None):
Bezleputh's avatar
Bezleputh committed
        return self.housing.go(_id=_id, noAudiotel=1).get_housing(obj=obj)