mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-06 17:44:09 +01:00
Added multiLoc support to Weather.cnn
This commit is contained in:
parent
163d835502
commit
e14a336b1d
@ -313,6 +313,7 @@ class Weather(callbacks.Privmsg):
|
|||||||
_cnnHumid = re.compile(r'Rel. Humidity: <b>(\d+%)</b>', re.I | re.S)
|
_cnnHumid = re.compile(r'Rel. Humidity: <b>(\d+%)</b>', re.I | re.S)
|
||||||
_cnnWind = re.compile(r'Wind: <b>([^<]+)</b>', re.I | re.S)
|
_cnnWind = re.compile(r'Wind: <b>([^<]+)</b>', re.I | re.S)
|
||||||
_cnnLoc = re.compile(r'<title>([^<]+)</title>', re.I | re.S)
|
_cnnLoc = re.compile(r'<title>([^<]+)</title>', re.I | re.S)
|
||||||
|
_cnnMultiLoc = re.compile(r'href="([^f]+forecast.jsp[^"]+)', re.I)
|
||||||
# Certain countries are expected to use a standard abbreviation
|
# Certain countries are expected to use a standard abbreviation
|
||||||
# The weather we pull uses weird codes. Map obvious ones here.
|
# The weather we pull uses weird codes. Map obvious ones here.
|
||||||
_cnnCountryMap = {'uk': 'en', 'de': 'ge'}
|
_cnnCountryMap = {'uk': 'en', 'de': 'ge'}
|
||||||
@ -338,9 +339,14 @@ class Weather(callbacks.Privmsg):
|
|||||||
url = '%s%s' % (self._cnnUrl, urllib.quote(loc))
|
url = '%s%s' % (self._cnnUrl, urllib.quote(loc))
|
||||||
text = webutils.getUrl(url) # Errors caught in callCommand.
|
text = webutils.getUrl(url) # Errors caught in callCommand.
|
||||||
if 'No search results' in text or \
|
if 'No search results' in text or \
|
||||||
'does not match a zip code' in text or \
|
'does not match a zip code' in text:
|
||||||
'several matching locations for' in text: # XXX Goto first.
|
|
||||||
self._noLocation()
|
self._noLocation()
|
||||||
|
elif 'several matching locations for' in text:
|
||||||
|
m = self._cnnMultiLoc.search(text)
|
||||||
|
if m:
|
||||||
|
text = webutils.getUrl(m.group(1))
|
||||||
|
else:
|
||||||
|
self._noLocation()
|
||||||
location = self._cnnLoc.search(text)
|
location = self._cnnLoc.search(text)
|
||||||
temp = self._cnnFTemp.search(text)
|
temp = self._cnnFTemp.search(text)
|
||||||
conds = self._cnnCond.search(text)
|
conds = self._cnnCond.search(text)
|
||||||
|
Loading…
Reference in New Issue
Block a user