From 5e39dbafa7e5276f3c5bbe13f90a3a7af627043d Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Thu, 13 Mar 2003 07:12:47 +0000 Subject: [PATCH] Added inkedmn's weather command. --- plugins/Http.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/plugins/Http.py b/plugins/Http.py index 299114e1b..2c576e7b1 100644 --- a/plugins/Http.py +++ b/plugins/Http.py @@ -170,5 +170,26 @@ class Http(callbacks.Privmsg): except urllib2.URLError: irc.error(msg, 'Couldn\'t open search page.') + + _tempregex = re.compile('CLASS=obsTempTextA>(\d+)°F',\ + re.IGNORECASE) + _cityregex = re.compile(r'Local Forecast for (.*), (.*?) ') + _condregex = re.compile('CLASS=obsInfo2>(.*)',\ + re.IGNORECASE) + def weather(self, irc, msg, args): + "" + 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