From e69766e71e1a0a36aeb1eaf507fabd2af16df960 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Fri, 5 Oct 2012 10:41:57 -0500 Subject: [PATCH] Weather: do ambiguous results prompt for forecast --- modules/Weather.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/modules/Weather.py b/modules/Weather.py index 7d68531..c8cb233 100644 --- a/modules/Weather.py +++ b/modules/Weather.py @@ -229,10 +229,24 @@ class Weather(Module): # just see if we have forecast data forecasts = forecast_data['forecast']['txt_forecast'] except KeyError as e: - # now we really know something is wrong - self.log.error("error or bad query in forecast 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}, {2:s}),".format(q, res['name'], + res['country_name']) + q = results[-1]['l'].strip('/q/') + reply += " or {0:s} ({1:s}, {2:s}).".format(q, results[-1]['name'], + results[-1]['country_name']) + return reply + except KeyError as e: + # now we really know something is wrong + self.log.error("error or bad query in forecast lookup") + self.log.exception(e) + return "No results." else: try: reply = "Forecast: "