From d26fc8d81f88f92eb798e28c49b9990dbc73bc14 Mon Sep 17 00:00:00 2001 From: "Sean B. Palmer" Date: Mon, 24 Nov 2008 21:14:22 +0000 Subject: [PATCH] Applied a patch to weather.py from Chris Waigl, and fixed search.py. --- modules/search.py | 5 ++--- modules/weather.py | 31 +++++++++++++++---------------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/modules/search.py b/modules/search.py index 8523832..37c7b86 100755 --- a/modules/search.py +++ b/modules/search.py @@ -31,9 +31,8 @@ def search(query): def result(query): results = search(query) - if results['responseData']: - return results['responseData']['results'][0]['unescapedUrl'] - return None + try: return results['responseData']['results'][0]['unescapedUrl'] + except IndexError: return None def count(query): results = search(query) diff --git a/modules/weather.py b/modules/weather.py index 787551c..232e58f 100755 --- a/modules/weather.py +++ b/modules/weather.py @@ -64,18 +64,21 @@ def local(icao, hour, minute): return str(hour) + ':' + str(minute) + 'Z' def code(phenny, search): - name, country, latitude, longitude = location(search) - if name == '?': return False - - sumOfSquares = (99999999999999999999999999999, 'ICAO') from icao import data - for icao_code, lat, lon in data: - latDiff = abs(latitude - lat) - lonDiff = abs(longitude - lon) - diff = (latDiff * latDiff) + (lonDiff * lonDiff) - if diff < sumOfSquares[0]: - sumOfSquares = (diff, icao_code) - return sumOfSquares[1] + + if search.upper() in [loc[0] for loc in data]: + return search.upper() + else: + name, country, latitude, longitude = location(search) + if name == '?': return False + sumOfSquares = (99999999999999999999999999999, 'ICAO') + for icao_code, lat, lon in data: + latDiff = abs(latitude - lat) + lonDiff = abs(longitude - lon) + diff = (latDiff * latDiff) + (lonDiff * lonDiff) + if diff < sumOfSquares[0]: + sumOfSquares = (diff, icao_code) + return sumOfSquares[1] @deprecated def f_weather(self, origin, match, args): @@ -87,11 +90,7 @@ def f_weather(self, origin, match, args): if not icao_code: return self.msg(origin.sender, 'Try .weather London, for example?') - if (not len(icao_code) == 4) or \ - (len(icao_code) > 1 and icao_code[0] in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' and - icao_code[1] in 'abcdefghijklmnopqrstuvwxyz'): - icao_code = code(self, icao_code) - else: icao_code = icao_code.upper() + icao_code = code(self, icao_code) if not icao_code: self.msg(origin.sender, 'No ICAO code found, sorry')