Browse Source

Deduplicate the available backends list

updated_weboob
Lucas Verney 5 years ago
parent
commit
64f6e8886b
  1. 19
      flatisfy/constants.py
  2. 4
      flatisfy/fetch.py
  3. 19
      flatisfy/filters/duplicates.py

19
flatisfy/constants.py

@ -0,0 +1,19 @@ @@ -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"
]

4
flatisfy/fetch.py

@ -11,6 +11,7 @@ import logging @@ -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): @@ -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"]

19
flatisfy/filters/duplicates.py

@ -16,24 +16,11 @@ import PIL.Image @@ -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): @@ -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): @@ -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

Loading…
Cancel
Save