Applied a patch to weather.py from Chris Waigl, and fixed search.py.

master
Sean B. Palmer 2008-11-24 21:14:22 +00:00
parent 4eb5bb8942
commit d26fc8d81f
2 changed files with 17 additions and 19 deletions

View File

@ -31,9 +31,8 @@ def search(query):
def result(query): def result(query):
results = search(query) results = search(query)
if results['responseData']: try: return results['responseData']['results'][0]['unescapedUrl']
return results['responseData']['results'][0]['unescapedUrl'] except IndexError: return None
return None
def count(query): def count(query):
results = search(query) results = search(query)

View File

@ -64,18 +64,21 @@ def local(icao, hour, minute):
return str(hour) + ':' + str(minute) + 'Z' return str(hour) + ':' + str(minute) + 'Z'
def code(phenny, search): def code(phenny, search):
name, country, latitude, longitude = location(search)
if name == '?': return False
sumOfSquares = (99999999999999999999999999999, 'ICAO')
from icao import data from icao import data
for icao_code, lat, lon in data:
latDiff = abs(latitude - lat) if search.upper() in [loc[0] for loc in data]:
lonDiff = abs(longitude - lon) return search.upper()
diff = (latDiff * latDiff) + (lonDiff * lonDiff) else:
if diff < sumOfSquares[0]: name, country, latitude, longitude = location(search)
sumOfSquares = (diff, icao_code) if name == '?': return False
return sumOfSquares[1] 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 @deprecated
def f_weather(self, origin, match, args): def f_weather(self, origin, match, args):
@ -87,11 +90,7 @@ def f_weather(self, origin, match, args):
if not icao_code: if not icao_code:
return self.msg(origin.sender, 'Try .weather London, for example?') return self.msg(origin.sender, 'Try .weather London, for example?')
if (not len(icao_code) == 4) or \ icao_code = code(self, icao_code)
(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()
if not icao_code: if not icao_code:
self.msg(origin.sender, 'No ICAO code found, sorry') self.msg(origin.sender, 'No ICAO code found, sorry')