From e4c7bc81b84ee33187b79facf7aed7b7aaeb966c Mon Sep 17 00:00:00 2001 From: James Lu Date: Sun, 4 Feb 2018 11:20:13 -0800 Subject: [PATCH] Weather: show names in 'locationsearch' again --- Weather/plugin.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/Weather/plugin.py b/Weather/plugin.py index a2eb9a5..bab10ac 100644 --- a/Weather/plugin.py +++ b/Weather/plugin.py @@ -297,7 +297,7 @@ class Weather(callbacks.Plugin): # WUNDERGROUND API CALLS # ########################## - def _wuac(self, q): + def _wuac(self, q, return_names=False): """Internal helper to find locations via Wunderground's GeoLookup API. Previous versions of this plugin used the Autocompete API instead.""" @@ -318,10 +318,21 @@ class Weather(callbacks.Plugin): if data.get('location'): # This form is used when there's only one result. 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: # 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 @@ -612,11 +623,11 @@ class Weather(callbacks.Plugin): irc.error("No Wunderground API key was defined; set 'config plugins.Weather.apiKey'.", Raise=True) - results = self._wuac(text) + results = self._wuac(text, return_names=True) if not results: irc.error("No results found.") else: - irc.reply(format('%L', results)) + irc.reply(format('%L', ('\x02{0}\x02: {1}'.format(*result) for result in results))) Class = Weather