Weather: do ambiguous results prompt for forecast

This commit is contained in:
Brian S. Stephan 2012-10-05 10:41:57 -05:00
parent 0da81ca31e
commit e69766e71e
1 changed files with 18 additions and 4 deletions

View File

@ -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: "