No longer make queries with more than three cities
Some postal codes correspond to multiple cities, then sometimes we were spawning queries with more than three cities. This should no longer be the case. This fixes https://github.com/Phyks/Flatisfy/issues/10.
This commit is contained in:
parent
c96b2a3f4c
commit
7fd44b7e8f
@ -95,7 +95,7 @@ class WeboobProxy(object):
|
|||||||
"""
|
"""
|
||||||
Build Weboob ``weboob.capabilities.housing.Query`` objects from the
|
Build Weboob ``weboob.capabilities.housing.Query`` objects from the
|
||||||
constraints defined in the configuration. Each query has at most 3
|
constraints defined in the configuration. Each query has at most 3
|
||||||
postal codes, to comply with housing websites limitations.
|
cities, to comply with housing websites limitations.
|
||||||
|
|
||||||
:param constraints_dict: A dictionary of constraints, as defined in the
|
:param constraints_dict: A dictionary of constraints, as defined in the
|
||||||
config.
|
config.
|
||||||
@ -103,11 +103,10 @@ class WeboobProxy(object):
|
|||||||
objects. Returns ``None`` if an error occurred.
|
objects. Returns ``None`` if an error occurred.
|
||||||
"""
|
"""
|
||||||
queries = []
|
queries = []
|
||||||
for postal_codes in tools.batch(constraints_dict["postal_codes"], 3):
|
|
||||||
query = Query()
|
# First, find all matching cities for the postal codes in constraints
|
||||||
query.cities = []
|
|
||||||
for postal_code in postal_codes:
|
|
||||||
matching_cities = []
|
matching_cities = []
|
||||||
|
for postal_code in constraints_dict["postal_codes"]:
|
||||||
try:
|
try:
|
||||||
for city in self.webnip.do("search_city", postal_code):
|
for city in self.webnip.do("search_city", postal_code):
|
||||||
matching_cities.append(city)
|
matching_cities.append(city)
|
||||||
@ -129,9 +128,10 @@ class WeboobProxy(object):
|
|||||||
postal_code
|
postal_code
|
||||||
)
|
)
|
||||||
|
|
||||||
# Append the matched cities to the query
|
# Then, build queries by grouping cities by at most 3
|
||||||
for city in matching_cities:
|
for cities_batch in tools.batch(matching_cities, 3):
|
||||||
query.cities.append(city)
|
query = Query()
|
||||||
|
query.cities = list(cities_batch)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
query.house_types = [
|
query.house_types = [
|
||||||
|
Loading…
Reference in New Issue
Block a user