From c7de979d792d4b15f0b08866977a42ddb4d794cf Mon Sep 17 00:00:00 2001 From: Yawar Siddiqui Date: Mon, 25 May 2020 22:24:48 +0200 Subject: [PATCH 1/3] Clean up enabling distance apis --- config.yaml.dist | 2 ++ flathunter/hunter.py | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/config.yaml.dist b/config.yaml.dist index 9312a1e0..792f0126 100644 --- a/config.yaml.dist +++ b/config.yaml.dist @@ -85,9 +85,11 @@ message: | # The URL should most probably just kept like that. # To use the Google Maps API, an API key is required. You can obtain one # without costs from the Google App Console (just google for it). +# Additionally, to enable the API calls in the code, set the 'enable' key to True google_maps_api: key: YOUR_API_KEY url: https://maps.googleapis.com/maps/api/distancematrix/json?origins={origin}&destinations={dest}&mode={mode}&sensor=true&key={key}&arrival_time={arrival} + enable: False # Sending messages using Telegram requires a Telegram Bot configured. # Telegram.org offers a good documentation about how to create a bot. diff --git a/flathunter/hunter.py b/flathunter/hunter.py index 0ff3151c..7293d392 100644 --- a/flathunter/hunter.py +++ b/flathunter/hunter.py @@ -58,7 +58,10 @@ def hunt_flats(self, searchers, id_watch): self.__log__.debug("Loaded address %s for url %s" % (address, url)) break - # calculdate durations + # calculate durations if enabled + if self.config.google_maps_api.enable: + durations = self.get_formatted_durations(self.config, address).strip() + message = self.config.get('message', "").format( title=expose['title'], rooms=expose['rooms'], @@ -66,9 +69,7 @@ def hunt_flats(self, searchers, id_watch): price=expose['price'], url=expose['url'], address=address, - durations="").strip() - # UNCOMMENT below and COMMENT Above to enable duration feature - # durations=self.get_formatted_durations(config, address)).strip() + durations="" if not self.config.google_maps_api.enable else durations).strip() # if no excludes, send messages if len(self.excluded_titles) == 0: From 786bbc91da61e6e52ea799a2952b947f99c56290 Mon Sep 17 00:00:00 2001 From: Yawar Siddiqui Date: Mon, 25 May 2020 22:42:19 +0200 Subject: [PATCH 2/3] Fix issues with config keys in commit c7de979d792d4b15f0b08866977a42ddb4d794cf --- flathunter/hunter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flathunter/hunter.py b/flathunter/hunter.py index 7293d392..10484e3b 100644 --- a/flathunter/hunter.py +++ b/flathunter/hunter.py @@ -59,7 +59,7 @@ def hunt_flats(self, searchers, id_watch): break # calculate durations if enabled - if self.config.google_maps_api.enable: + if self.config["google_maps_api"]["enable"]: durations = self.get_formatted_durations(self.config, address).strip() message = self.config.get('message', "").format( @@ -69,7 +69,7 @@ def hunt_flats(self, searchers, id_watch): price=expose['price'], url=expose['url'], address=address, - durations="" if not self.config.google_maps_api.enable else durations).strip() + durations="" if not self.config["google_maps_api"]["enable"] else durations).strip() # if no excludes, send messages if len(self.excluded_titles) == 0: From 41555362f1d37a1f63e21d275061f311c82e4872 Mon Sep 17 00:00:00 2001 From: Yawar Siddiqui Date: Mon, 25 May 2020 23:10:38 +0200 Subject: [PATCH 3/3] Support minimal config for tests --- flathunter/hunter.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/flathunter/hunter.py b/flathunter/hunter.py index 10484e3b..ced8cb6f 100644 --- a/flathunter/hunter.py +++ b/flathunter/hunter.py @@ -59,7 +59,8 @@ def hunt_flats(self, searchers, id_watch): break # calculate durations if enabled - if self.config["google_maps_api"]["enable"]: + durations_enabled = "google_maps_api" in self.config and self.config["google_maps_api"]["enable"] + if durations_enabled: durations = self.get_formatted_durations(self.config, address).strip() message = self.config.get('message', "").format( @@ -69,7 +70,7 @@ def hunt_flats(self, searchers, id_watch): price=expose['price'], url=expose['url'], address=address, - durations="" if not self.config["google_maps_api"]["enable"] else durations).strip() + durations="" if not durations_enabled else durations).strip() # if no excludes, send messages if len(self.excluded_titles) == 0: