From e7c81d31acdb70bff896672d18c6739428029dcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Le=20Garrec=24?= Date: Tue, 24 Oct 2017 17:21:48 +0200 Subject: [PATCH] Add config option for minimum number of pictures --- flatisfy/config.py | 5 +++++ flatisfy/filters/__init__.py | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/flatisfy/config.py b/flatisfy/config.py index 7f4bc28..1e92378 100644 --- a/flatisfy/config.py +++ b/flatisfy/config.py @@ -34,6 +34,7 @@ DEFAULT_CONFIG = { "cost": (None, None), # (min, max) in currency unit "rooms": (None, None), # (min, max) "bedrooms": (None, None), # (min, max) + "minimum_pictures": None, "time_to": {} # Dict mapping names to {"gps": [lat, lng], # "time": (min, max) } # Time is in seconds @@ -136,6 +137,10 @@ def validate_config(config, check_with_data): assert "type" in constraint assert isinstance(constraint["type"], str) assert constraint["type"].upper() in ["RENT", "SALE", "SHARING"] + + assert "minimum_pictures" in constraint + assert isinstance(constraint["minimum_pictures"], int) + assert constraint["minimum_pictures"] >= 0 assert "house_types" in constraint assert constraint["house_types"] diff --git a/flatisfy/filters/__init__.py b/flatisfy/filters/__init__.py index 0086dde..34c064e 100644 --- a/flatisfy/filters/__init__.py +++ b/flatisfy/filters/__init__.py @@ -67,6 +67,12 @@ def refine_with_housing_criteria(flats_list, constraint): field.capitalize(), flat["id"]) is_ok[i] = is_ok[i] and is_within_interval + # Check number of pictures + print(constraint['minimum_pictures'], len(flat['photos'])) + if not (constraint['minimum_pictures'] <= len(flat['photos'])): + is_ok[i] = False + + return ( [ flat