From 41c1a46bb2e917eaacf15b0ce6c8368bc031e6b6 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Mon, 17 Sep 2012 16:47:41 -0500 Subject: [PATCH] Weather: give hints when results are ambiguous --- modules/Weather.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/modules/Weather.py b/modules/Weather.py index c884f32..a29f26c 100644 --- a/modules/Weather.py +++ b/modules/Weather.py @@ -111,9 +111,22 @@ class Weather(Module): # just see if we have current_observation data current = condition_data['current_observation'] except KeyError as e: - self.log.error("error or bad query in conditions lookup") - self.log.exception(e) - return "No results." + # ok, try to see if the ambiguous results stuff will help + self.log.debug("potentially ambiguous results, checking") + try: + results = condition_data['response']['results'] + reply = "Multiple results, try one of the following zmw codes:" + for res in results[:-1]: + q = res['l'].strip('/q/') + reply += " {0:s} ({1:s}),".format(q, res['name']) + q = results[-1]['l'].strip('/q/') + reply += " or {0:s} ({1:s}).".format(q, results[-1]['name']) + return reply + except KeyError as e: + # now we really know something is wrong + self.log.error("error or bad query in conditions lookup") + self.log.exception(e) + return "No results." else: try: location = current['display_location']['full']