mirror of
https://github.com/jlu5/SupyPlugins.git
synced 2025-04-26 21:11:14 -05:00
Weather: show names in 'locationsearch' again
This commit is contained in:
parent
1134e8474d
commit
e4c7bc81b8
@ -297,7 +297,7 @@ class Weather(callbacks.Plugin):
|
|||||||
# WUNDERGROUND API CALLS #
|
# WUNDERGROUND API CALLS #
|
||||||
##########################
|
##########################
|
||||||
|
|
||||||
def _wuac(self, q):
|
def _wuac(self, q, return_names=False):
|
||||||
"""Internal helper to find locations via Wunderground's GeoLookup API.
|
"""Internal helper to find locations via Wunderground's GeoLookup API.
|
||||||
Previous versions of this plugin used the Autocompete API instead."""
|
Previous versions of this plugin used the Autocompete API instead."""
|
||||||
|
|
||||||
@ -318,10 +318,21 @@ class Weather(callbacks.Plugin):
|
|||||||
if data.get('location'):
|
if data.get('location'):
|
||||||
# This form is used when there's only one result.
|
# This form is used when there's only one result.
|
||||||
zmw = 'zmw:{zip}.{magic}.{wmo}'.format(**data['location'])
|
zmw = 'zmw:{zip}.{magic}.{wmo}'.format(**data['location'])
|
||||||
return [zmw]
|
if return_names:
|
||||||
|
name = '{city}, {country_name}'.format(**data['location'])
|
||||||
|
return [(name, zmw)]
|
||||||
|
else:
|
||||||
|
return [zmw]
|
||||||
else:
|
else:
|
||||||
# This form of result is returned there are multiple places matching a query
|
# This form of result is returned there are multiple places matching a query
|
||||||
results = [('zmw:' + result['zmw']) for result in data['response'].get('results', [])]
|
results = data['response'].get('results')
|
||||||
|
if not results:
|
||||||
|
return []
|
||||||
|
|
||||||
|
if return_names:
|
||||||
|
results = [('{name}, {country_name}'.format(**result), 'zmw:' + result['zmw']) for result in results]
|
||||||
|
else:
|
||||||
|
results = [('zmw:' + result['zmw']) for result in results]
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
@ -612,11 +623,11 @@ class Weather(callbacks.Plugin):
|
|||||||
irc.error("No Wunderground API key was defined; set 'config plugins.Weather.apiKey'.",
|
irc.error("No Wunderground API key was defined; set 'config plugins.Weather.apiKey'.",
|
||||||
Raise=True)
|
Raise=True)
|
||||||
|
|
||||||
results = self._wuac(text)
|
results = self._wuac(text, return_names=True)
|
||||||
if not results:
|
if not results:
|
||||||
irc.error("No results found.")
|
irc.error("No results found.")
|
||||||
else:
|
else:
|
||||||
irc.reply(format('%L', results))
|
irc.reply(format('%L', ('\x02{0}\x02: {1}'.format(*result) for result in results)))
|
||||||
|
|
||||||
Class = Weather
|
Class = Weather
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user