Browse Source

Reduce logs verbosity

master
Gautier P 2 years ago
parent
commit
582a868a1d
  1. 34
      flatisfy/cmds.py
  2. 24
      flatisfy/filters/__init__.py

34
flatisfy/cmds.py

@ -23,9 +23,7 @@ import time @@ -23,9 +23,7 @@ import time
LOGGER = logging.getLogger(__name__)
def filter_flats_list(
config, constraint_name, flats_list, fetch_details=True, past_flats=None
):
def filter_flats_list(config, constraint_name, flats_list, fetch_details=True, past_flats=None):
"""
Filter the available flats list. Then, filter it according to criteria.
@ -69,7 +67,7 @@ def filter_flats_list( @@ -69,7 +67,7 @@ def filter_flats_list(
use_cache = past_ids.get(flat["id"])
if use_cache:
LOGGER.info("Skipping details download for %s.", flat["id"])
LOGGER.debug("Skipping details download for %s.", flat["id"])
details = use_cache
else:
details = fetch.fetch_details(config, flat["id"])
@ -82,32 +80,22 @@ def filter_flats_list( @@ -82,32 +80,22 @@ def filter_flats_list(
# Do a second pass to consolidate all the infos we found and make use of
# additional infos
if config["passes"] > 1:
second_pass_result = flatisfy.filters.second_pass(
first_pass_result["new"], constraint, config
)
second_pass_result = flatisfy.filters.second_pass(first_pass_result["new"], constraint, config)
else:
second_pass_result["new"] = first_pass_result["new"]
# Do a third pass to deduplicate better
if config["passes"] > 2:
third_pass_result = flatisfy.filters.third_pass(
second_pass_result["new"], config
)
third_pass_result = flatisfy.filters.third_pass(second_pass_result["new"], config)
else:
third_pass_result["new"] = second_pass_result["new"]
return {
"new": third_pass_result["new"],
"duplicate": (
first_pass_result["duplicate"]
+ second_pass_result["duplicate"]
+ third_pass_result["duplicate"]
),
"ignored": (
first_pass_result["ignored"]
+ second_pass_result["ignored"]
+ third_pass_result["ignored"]
first_pass_result["duplicate"] + second_pass_result["duplicate"] + third_pass_result["duplicate"]
),
"ignored": (first_pass_result["ignored"] + second_pass_result["ignored"] + third_pass_result["ignored"]),
}
@ -178,10 +166,7 @@ def import_and_filter(config, load_from_db=False, new_only=False): @@ -178,10 +166,7 @@ def import_and_filter(config, load_from_db=False, new_only=False):
for status, flats_list in flatten_flats_by_status.items():
# Build SQLAlchemy Flat model objects for every available flat
flats_objects = {
flat_dict["id"]: flat_model.Flat.from_dict(flat_dict)
for flat_dict in flats_list
}
flats_objects = {flat_dict["id"]: flat_model.Flat.from_dict(flat_dict) for flat_dict in flats_list}
if flats_objects:
# If there are some flats, try to merge them with the ones in
@ -266,8 +251,5 @@ def serve(config): @@ -266,8 +251,5 @@ def serve(config):
# standard logging
server = web_app.QuietWSGIRefServer
print(
"Launching web viewer running on http://%s:%s"
% (config["host"], config["port"])
)
print("Launching web viewer running on http://%s:%s" % (config["host"], config["port"]))
app.run(host=config["host"], port=config["port"], server=server)

24
flatisfy/filters/__init__.py

@ -37,15 +37,13 @@ def refine_with_housing_criteria(flats_list, constraint): @@ -37,15 +37,13 @@ def refine_with_housing_criteria(flats_list, constraint):
# Check postal code
postal_code = flat["flatisfy"].get("postal_code", None)
if postal_code and postal_code not in constraint["postal_codes"]:
LOGGER.info("Postal code for flat %s is out of range.", flat["id"])
LOGGER.info("Postal code %s for flat %s is out of range.", postal_code, flat["id"])
is_ok[i] = is_ok[i] and False
# Check time_to
for place_name, time in flat["flatisfy"].get("time_to", {}).items():
time = time["time"]
is_within_interval = tools.is_within_interval(
time, *(constraint["time_to"][place_name]["time"])
)
is_within_interval = tools.is_within_interval(time, *(constraint["time_to"][place_name]["time"]))
if not is_within_interval:
LOGGER.info(
"Flat %s is too far from place %s: %ds.",
@ -58,12 +56,10 @@ def refine_with_housing_criteria(flats_list, constraint): @@ -58,12 +56,10 @@ def refine_with_housing_criteria(flats_list, constraint):
# Check other fields
for field in ["area", "cost", "rooms", "bedrooms"]:
interval = constraint[field]
is_within_interval = tools.is_within_interval(
flat.get(field, None), *interval
)
is_within_interval = tools.is_within_interval(flat.get(field, None), *interval)
if not is_within_interval:
LOGGER.info(
"%s for flat %s is out of range.", field.capitalize(), flat["id"]
"%s %s for flat %s is out of range.", field.capitalize(), str(flat.get(field, None)), flat["id"]
)
is_ok[i] = is_ok[i] and is_within_interval
@ -95,9 +91,7 @@ def refine_with_details_criteria(flats_list, constraint): @@ -95,9 +91,7 @@ def refine_with_details_criteria(flats_list, constraint):
for i, flat in enumerate(flats_list):
# Check number of pictures
has_enough_photos = tools.is_within_interval(
len(flat.get("photos", [])), constraint["minimum_nb_photos"], None
)
has_enough_photos = tools.is_within_interval(len(flat.get("photos", [])), constraint["minimum_nb_photos"], None)
if not has_enough_photos:
LOGGER.info(
"Flat %s only has %d photos, it should have at least %d.",
@ -148,16 +142,12 @@ def first_pass(flats_list, constraint, config): @@ -148,16 +142,12 @@ def first_pass(flats_list, constraint, config):
# Handle duplicates based on ids
# Just remove them (no merge) as they should be the exact same object.
flats_list, _ = duplicates.detect(
flats_list, key="id", merge=False, should_intersect=False
)
flats_list, _ = duplicates.detect(flats_list, key="id", merge=False, should_intersect=False)
# Also merge duplicates based on urls (these may come from different
# flatboob backends)
# This is especially useful as some websites such as entreparticuliers
# contains a lot of leboncoin housings posts.
flats_list, duplicates_by_urls = duplicates.detect(
flats_list, key="urls", merge=True, should_intersect=True
)
flats_list, duplicates_by_urls = duplicates.detect(flats_list, key="urls", merge=True, should_intersect=True)
# Guess the postal codes
flats_list = metadata.guess_postal_code(flats_list, constraint, config)

Loading…
Cancel
Save