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..ced8cb6f 100644 --- a/flathunter/hunter.py +++ b/flathunter/hunter.py @@ -58,7 +58,11 @@ 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 + 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( title=expose['title'], rooms=expose['rooms'], @@ -66,9 +70,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 durations_enabled else durations).strip() # if no excludes, send messages if len(self.excluded_titles) == 0: