flatisfy/modules/foncia/browser.py

62 lines
2.0 KiB
Python
Raw Normal View History

2021-03-28 18:59:07 +02:00
# -*- coding: utf-8 -*-
# Copyright(C) 2017 Phyks (Lucas Verney)
#
2021-04-08 20:08:23 +02:00
# This file is part of a woob module.
2021-03-28 18:59:07 +02:00
#
2021-04-08 20:08:23 +02:00
# This woob module is free software: you can redistribute it and/or modify
2021-03-28 18:59:07 +02:00
# 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.
#
2021-04-08 20:08:23 +02:00
# This woob module is distributed in the hope that it will be useful,
2021-03-28 18:59:07 +02:00
# 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
2021-04-08 20:08:23 +02:00
# along with this woob module. If not, see <http://www.gnu.org/licenses/>.
2021-03-28 18:59:07 +02:00
from __future__ import unicode_literals
2021-04-08 20:08:23 +02:00
from woob.browser import PagesBrowser, URL
2021-03-28 18:59:07 +02:00
from .constants import QUERY_TYPES
from .pages import CitiesPage, HousingPage, SearchPage, SearchResultsPage
class FonciaBrowser(PagesBrowser):
BASEURL = 'https://fr.foncia.com'
cities = URL(r'/recherche/autocomplete\?term=(?P<term>.+)', CitiesPage)
housing = URL(r'/(?P<type>[^/]+)/.*\d+.htm', HousingPage)
search_results = URL(r'/(?P<type>[^/]+)/.*', SearchResultsPage)
search = URL(r'/(?P<type>.+)', SearchPage)
def get_cities(self, pattern):
"""
Get cities matching a given pattern.
"""
return self.cities.open(term=pattern).iter_cities()
def search_housings(self, query, cities):
"""
Search for housings matching given query.
"""
try:
query_type = QUERY_TYPES[query.type]
except KeyError:
return []
self.search.go(type=query_type).do_search(query, cities)
return self.page.iter_housings(query_type=query.type)
def get_housing(self, housing):
"""
Get specific housing.
"""
query_type, housing = housing.split(':')
self.search.go(type=query_type).find_housing(query_type, housing)
return self.page.get_housing()