Weather: give hints when results are ambiguous
This commit is contained in:
parent
b17de69a93
commit
41c1a46bb2
|
@ -111,9 +111,22 @@ class Weather(Module):
|
||||||
# just see if we have current_observation data
|
# just see if we have current_observation data
|
||||||
current = condition_data['current_observation']
|
current = condition_data['current_observation']
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
self.log.error("error or bad query in conditions lookup")
|
# ok, try to see if the ambiguous results stuff will help
|
||||||
self.log.exception(e)
|
self.log.debug("potentially ambiguous results, checking")
|
||||||
return "No results."
|
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:
|
else:
|
||||||
try:
|
try:
|
||||||
location = current['display_location']['full']
|
location = current['display_location']['full']
|
||||||
|
|
Loading…
Reference in New Issue