mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-26 20:59:27 +01:00
Added inkedmn's weather command.
This commit is contained in:
parent
c4a577c9c2
commit
5e39dbafa7
@ -171,4 +171,25 @@ class Http(callbacks.Privmsg):
|
|||||||
irc.error(msg, 'Couldn\'t open search page.')
|
irc.error(msg, 'Couldn\'t open search page.')
|
||||||
|
|
||||||
|
|
||||||
|
_tempregex = re.compile('CLASS=obsTempTextA>(\d+)°F</b></td>',\
|
||||||
|
re.IGNORECASE)
|
||||||
|
_cityregex = re.compile(r'Local Forecast for (.*), (.*?) ')
|
||||||
|
_condregex = re.compile('CLASS=obsInfo2><b CLASS=obsTextA>(.*)</b></td>',\
|
||||||
|
re.IGNORECASE)
|
||||||
|
def weather(self, irc, msg, args):
|
||||||
|
"<US zip code>"
|
||||||
|
zip = privmsgs.getArgs(args)
|
||||||
|
url = "http://www.weather.com/weather/local/%s?lswe=%s" % (zip, zip)
|
||||||
|
try:
|
||||||
|
html = urllib2.urlopen(url).read()
|
||||||
|
city, state = _cityregex.search(html).groups()
|
||||||
|
temp = _tempregex.search(html).group(1)
|
||||||
|
conds = _condregex.search(html).group(1)
|
||||||
|
irc.reply(msg, 'The current temperature in %s, %s is %dF with %s\
|
||||||
|
conditions' % (city, state, int(temp), conds))
|
||||||
|
except AttributeError:
|
||||||
|
irc.error(msg, 'the format of the page was odd.')
|
||||||
|
except urllib2.URLError:
|
||||||
|
irc.error(msg, 'Couldn\'t open the search page.')
|
||||||
|
|
||||||
Class = Http
|
Class = Http
|
||||||
|
Loading…
Reference in New Issue
Block a user