From bfc27bbb92605479f616258069c1c9e6c167a77a Mon Sep 17 00:00:00 2001 From: "Phyks (Lucas Verney)" Date: Wed, 7 Feb 2018 19:54:39 +0100 Subject: [PATCH] Update Flatisfy to handle the latest dev version of Weboob. Fixes #91 and #85. --- doc/0.getting_started.md | 3 ++- doc/_static/.gitkeep | 0 flatisfy/config.py | 5 +++-- flatisfy/fetch.py | 13 ++++++++----- flatisfy/filters/duplicates.py | 2 +- 5 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 doc/_static/.gitkeep diff --git a/doc/0.getting_started.md b/doc/0.getting_started.md index 03850aa..24cd98b 100644 --- a/doc/0.getting_started.md +++ b/doc/0.getting_started.md @@ -144,7 +144,8 @@ You should specify some constraints to filter the resulting housings list, under the `constraints` key. The available constraints are: * `type` is the type of housing you want, either `RENT` (to rent), `SALE` (to - buy) or `SHARING` (for a shared housing). + buy), `SHARING` (for a shared housing), `FURNISHED_RENT` (for a furnished + rent), `VIAGER` (for a viager, lifetime sale). * `house_types` is a list of house types you are looking for. Values can be `APART` (flat), `HOUSE`, `PARKING`, `LAND`, `OTHER` (everything else) or `UNKNOWN` (anything which was not matched with one of the previous diff --git a/doc/_static/.gitkeep b/doc/_static/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/flatisfy/config.py b/flatisfy/config.py index e9c01ac..c9dfd32 100644 --- a/flatisfy/config.py +++ b/flatisfy/config.py @@ -15,6 +15,7 @@ import sys import traceback import appdirs +from weboob.capabilities.housing import POSTS_TYPES, HOUSE_TYPES from flatisfy import data from flatisfy import tools @@ -155,7 +156,7 @@ def validate_config(config, check_with_data): for constraint in config["constraints"].values(): assert "type" in constraint assert isinstance(constraint["type"], str) - assert constraint["type"].upper() in ["RENT", "SALE", "SHARING"] + assert constraint["type"].upper() in POSTS_TYPES.keys assert "minimum_nb_photos" in constraint if constraint["minimum_nb_photos"]: @@ -171,7 +172,7 @@ def validate_config(config, check_with_data): assert "house_types" in constraint assert constraint["house_types"] for house_type in constraint["house_types"]: - assert house_type.upper() in ["APART", "HOUSE", "PARKING", "LAND", "OTHER", "UNKNOWN"] # noqa: E501 + assert house_type.upper() in HOUSE_TYPES.keys assert "postal_codes" in constraint assert constraint["postal_codes"] diff --git a/flatisfy/fetch.py b/flatisfy/fetch.py index 3a79b7e..4443d15 100644 --- a/flatisfy/fetch.py +++ b/flatisfy/fetch.py @@ -19,7 +19,7 @@ LOGGER = logging.getLogger(__name__) try: - from weboob.capabilities.housing import Query + from weboob.capabilities.housing import Query, POSTS_TYPES, HOUSE_TYPES from weboob.core.bcall import CallErrors from weboob.core.ouiboube import WebNip from weboob.tools.json import WeboobEncoder @@ -146,7 +146,7 @@ class WeboobProxy(object): try: query.house_types = [ getattr( - Query.HOUSE_TYPES, + HOUSE_TYPES, house_type.upper() ) for house_type in constraints_dict["house_types"] @@ -157,8 +157,8 @@ class WeboobProxy(object): try: query.type = getattr( - Query, - "TYPE_{}".format(constraints_dict["type"].upper()) + POSTS_TYPES, + constraints_dict["type"].upper() ) except AttributeError: LOGGER.error("Invalid post type constraint.") @@ -227,9 +227,12 @@ class WeboobProxy(object): housing = backend.get_housing(flat_id) # Otherwise, we miss the @backend afterwards housing.id = full_flat_id - # Eventually clear personal data if not store_personal_data: + # Ensure phone is cleared housing.phone = None + else: + # Ensure phone is fetched + backend.fillobj(housing, 'phone') return json.dumps(housing, cls=WeboobEncoder) except Exception as exc: # pylint: disable=broad-except diff --git a/flatisfy/filters/duplicates.py b/flatisfy/filters/duplicates.py index cb4b67d..035c476 100644 --- a/flatisfy/filters/duplicates.py +++ b/flatisfy/filters/duplicates.py @@ -82,7 +82,7 @@ def compare_photos(photo1, photo2, photo_cache, hash_threshold): :param photo2: Second photo url. :param photo_cache: An instance of ``ImageCache`` to use to cache images. :param hash_threshold: The hash threshold between two images. Usually two - different photos have a hash difference of 30. + different photos have a hash difference of 30. :return: ``True`` if the photos are identical, else ``False``. """ try: