Weather: give hints when results are ambiguous

tmp/79b4e7d7e0424f8155715d7c458859a1/head
Brian S. Stephan 11 years ago
parent b17de69a93
commit 41c1a46bb2

@ -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']

Loading…
Cancel
Save