From 64f6e8886b4f65c6a228f07b04a2ae4348e7b8ae Mon Sep 17 00:00:00 2001 From: "Phyks (Lucas Verney)" Date: Mon, 27 Nov 2017 15:05:13 +0100 Subject: [PATCH] Deduplicate the available backends list --- flatisfy/constants.py | 19 +++++++++++++++++++ flatisfy/fetch.py | 4 ++-- flatisfy/filters/duplicates.py | 19 +++---------------- 3 files changed, 24 insertions(+), 18 deletions(-) create mode 100644 flatisfy/constants.py diff --git a/flatisfy/constants.py b/flatisfy/constants.py new file mode 100644 index 0000000..c0aa919 --- /dev/null +++ b/flatisfy/constants.py @@ -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" +] diff --git a/flatisfy/fetch.py b/flatisfy/fetch.py index f35a52e..3059055 100644 --- a/flatisfy/fetch.py +++ b/flatisfy/fetch.py @@ -11,6 +11,7 @@ import logging from flatisfy import database from flatisfy import tools +from flatisfy.constants import BACKENDS_BY_PRECEDENCE from flatisfy.models import flat as flat_model LOGGER = logging.getLogger(__name__) @@ -67,8 +68,7 @@ class WeboobProxy(object): """ # Default backends if not config["backends"]: - backends = ["foncia", "seloger", "pap", "leboncoin", "logicimmo", - "explorimmo", "entreparticuliers"] + backends = BACKENDS_BY_PRECEDENCE else: backends = config["backends"] diff --git a/flatisfy/filters/duplicates.py b/flatisfy/filters/duplicates.py index 02420e0..28c94d3 100644 --- a/flatisfy/filters/duplicates.py +++ b/flatisfy/filters/duplicates.py @@ -16,24 +16,11 @@ import PIL.Image import requests from flatisfy import tools +from flatisfy.constants import BACKENDS_BY_PRECEDENCE from flatisfy.filters.cache import ImageCache 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): """ @@ -145,7 +132,7 @@ def detect(flats_list, key="id", merge=True, should_intersect=False): # Sort matching flats by backend precedence matching_flats.sort( 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) ), reverse=True @@ -312,7 +299,7 @@ def deep_detect(flats_list): if flat["id"] in matching_flats[flat_id] ], 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) ), reverse=True