Deduplicate the available backends list

This commit is contained in:
Lucas Verney 2017-11-27 15:05:13 +01:00
parent 5aff18e106
commit 64f6e8886b
3 changed files with 24 additions and 18 deletions

19
flatisfy/constants.py Normal file
View File

@ -0,0 +1,19 @@
# coding: utf-8
"""
Constants used across the app.
"""
from __future__ import absolute_import, print_function, unicode_literals
# Some backends give more infos than others. Here is the precedence we want to
# use. First is most important one, last is the one that will always be
# considered as less trustable if two backends have similar info about a
# housing.
BACKENDS_BY_PRECEDENCE = [
"foncia",
"seloger",
"pap",
"leboncoin",
"explorimmo",
"logicimmo",
"entreparticuliers"
]

View File

@ -11,6 +11,7 @@ import logging
from flatisfy import database from flatisfy import database
from flatisfy import tools from flatisfy import tools
from flatisfy.constants import BACKENDS_BY_PRECEDENCE
from flatisfy.models import flat as flat_model from flatisfy.models import flat as flat_model
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
@ -67,8 +68,7 @@ class WeboobProxy(object):
""" """
# Default backends # Default backends
if not config["backends"]: if not config["backends"]:
backends = ["foncia", "seloger", "pap", "leboncoin", "logicimmo", backends = BACKENDS_BY_PRECEDENCE
"explorimmo", "entreparticuliers"]
else: else:
backends = config["backends"] backends = config["backends"]

View File

@ -16,24 +16,11 @@ import PIL.Image
import requests import requests
from flatisfy import tools from flatisfy import tools
from flatisfy.constants import BACKENDS_BY_PRECEDENCE
from flatisfy.filters.cache import ImageCache from flatisfy.filters.cache import ImageCache
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
# Some backends give more infos than others. Here is the precedence we want to
# use. First is most important one, last is the one that will always be
# considered as less trustable if two backends have similar info about a
# housing.
BACKENDS_PRECEDENCE = [
"foncia",
"seloger",
"pap",
"leboncoin",
"explorimmo",
"logicimmo",
"entreparticuliers"
]
def homogeneize_phone_number(number): def homogeneize_phone_number(number):
""" """
@ -145,7 +132,7 @@ def detect(flats_list, key="id", merge=True, should_intersect=False):
# Sort matching flats by backend precedence # Sort matching flats by backend precedence
matching_flats.sort( matching_flats.sort(
key=lambda flat: next( key=lambda flat: next(
i for (i, backend) in enumerate(BACKENDS_PRECEDENCE) i for (i, backend) in enumerate(BACKENDS_BY_PRECEDENCE)
if flat["id"].endswith(backend) if flat["id"].endswith(backend)
), ),
reverse=True reverse=True
@ -312,7 +299,7 @@ def deep_detect(flats_list):
if flat["id"] in matching_flats[flat_id] if flat["id"] in matching_flats[flat_id]
], ],
key=lambda flat: next( key=lambda flat: next(
i for (i, backend) in enumerate(BACKENDS_PRECEDENCE) i for (i, backend) in enumerate(BACKENDS_BY_PRECEDENCE)
if flat["id"].endswith(backend) if flat["id"].endswith(backend)
), ),
reverse=True reverse=True