Fixed the problem where country abbreviations that match USA State

abbreviations will never be found.

Arizona seemed to be missing from our _realStates set.  It's in there now.

Added a _mapCountries to map 'obviously' debatable country abbreviations.
(Just have uk->gb in there at the moment.  I probably missed a few).
This commit is contained in:
Brett Phipps 2003-11-20 05:27:03 +00:00
parent 6106f27e2d
commit e21d7109cb

View File

@ -147,16 +147,20 @@ class Http(callbacks.Privmsg):
r'<td valign="top" align="right"><strong><font face="arial">'\ r'<td valign="top" align="right"><strong><font face="arial">'\
r'(.*?)</font></strong></td>', re.IGNORECASE) r'(.*?)</font></strong></td>', re.IGNORECASE)
# States # States
_realStates = sets.Set(['ak', 'al', 'ar', 'ca', 'co', 'ct', 'dc', _realStates = sets.Set(['ak', 'al', 'ar', 'az', 'ca', 'co', 'ct',
'de', 'fl', 'ga', 'hi', 'ia', 'id', 'il', 'dc', 'de', 'fl', 'ga', 'hi', 'ia', 'id',
'in', 'ks', 'ky', 'la', 'ma', 'md', 'me', 'il', 'in', 'ks', 'ky', 'la', 'ma', 'md',
'mi', 'mn', 'mo', 'ms', 'mt', 'nc', 'nd', 'me', 'mi', 'mn', 'mo', 'ms', 'mt', 'nc',
'ne', 'nh', 'nj', 'nm', 'nv', 'ny', 'oh', 'nd', 'ne', 'nh', 'nj', 'nm', 'nv', 'ny',
'ok', 'or', 'pa', 'ri', 'sc', 'sd', 'tn', 'oh', 'ok', 'or', 'pa', 'ri', 'sc', 'sd',
'tx', 'ut', 'va', 'vt', 'wa', 'wi', 'wv', 'wy']) 'tn', 'tx', 'ut', 'va', 'vt', 'wa', 'wi',
'wv', 'wy'])
# Provinces. (Province being a metric state measurement mind you. :D) # Provinces. (Province being a metric state measurement mind you. :D)
_fakeStates = sets.Set(['ab', 'bc', 'mb', 'nb', 'nf', 'ns', 'nt', _fakeStates = sets.Set(['ab', 'bc', 'mb', 'nb', 'nf', 'ns', 'nt',
'nu', 'on', 'pe', 'qc', 'sk', 'yk']) 'nu', 'on', 'pe', 'qc', 'sk', 'yk'])
# Certain countries are expected to use a standard abbreviation
# The weather we pull uses weird codes. Map obvious ones here.
_countryMap = {'uk': 'gb'}
def weather(self, irc, msg, args): def weather(self, irc, msg, args):
"""<US zip code> <US/Canada city, state> <Foreign city, country> """<US zip code> <US/Canada city, state> <Foreign city, country>
@ -186,11 +190,23 @@ class Http(callbacks.Privmsg):
else: else:
country = state country = state
state = '' state = ''
if country in self._countryMap.keys():
country = self._countryMap[country]
url = 'http://www.hamweather.net/cgi-bin/hw3/hw3.cgi?'\ url = 'http://www.hamweather.net/cgi-bin/hw3/hw3.cgi?'\
'pass=&dpp=&forecast=zandh&config=&'\ 'pass=&dpp=&forecast=zandh&config=&'\
'place=%s&state=%s&country=%s' % \ 'place=%s&state=%s&country=%s' % \
(city, state, country) (city, state, country)
#debug.printf(url) #debug.printf(url)
html = getPage(url)
if 'was not found' in html:
url = 'http://www.hamweather.net/cgi-bin/hw3/hw3.cgi?'\
'pass=&dpp=&forecast=zandh&config=&'\
'place=%s&state=&country=%s' % \
(city, state)
html = getPage(url)
if 'was not found' in html:
irc.error(msg, 'No such location could be found.')
return
#We received a single argument. Zipcode or station id. #We received a single argument. Zipcode or station id.
else: else:
@ -199,12 +215,11 @@ class Http(callbacks.Privmsg):
zip = zip.lower().split() zip = zip.lower().split()
url = 'http://www.hamweather.net/cgi-bin/hw3/hw3.cgi?'\ url = 'http://www.hamweather.net/cgi-bin/hw3/hw3.cgi?'\
'config=&forecast=zandh&pands=%s&Submit=GO' % args[0] 'config=&forecast=zandh&pands=%s&Submit=GO' % args[0]
#debug.printf(url)
html = getPage(url) html = getPage(url)
if 'was not found' in html: if 'was not found' in html:
irc.error(msg, 'No such location could be found.') irc.error(msg, 'No such location could be found.')
return return
headData = self._cityregex.search(html) headData = self._cityregex.search(html)
if headData: if headData:
(city, state, country) = headData.groups() (city, state, country) = headData.groups()