"
search = '+'.join([urllib.quote(arg) for arg in args])
url = 'http://foldoc.doc.ic.ac.uk/foldoc/foldoc.cgi?query=%s' % search
try:
fd = urllib2.urlopen(url)
html = fd.read()
fd.close()
except Exception, e:
irc.error(msg, debug.exnToString(e))
text = html.split('\n', 2)[1]
text = text.replace('.\n', '. ')
text = text.replace('\n', ' ')
text = self._html.sub('', text)
irc.reply(msg, text.strip())
_gkrating = re.compile(r'(\d+)')
_gkgames = re.compile(r's:
(\d+) | ')
_gkrecord = re.compile(r'"#FFFF00">(\d+)[^"]+"#FFFF00">(\d+)[^"]+'\
'"#FFFF00">(\d+)')
_gkteam = re.compile('Team:([^\s]+)')
_gkseen = re.compile('seen on GK: ([^\n]+)')
def gkstats(self, irc, msg, args):
""
name = privmsgs.getArgs(args)
gkprofile = 'http://www.gameknot.com/stats.pl?%s' % name
try:
fd = urllib2.urlopen(gkprofile)
profile = fd.read()
fd.close()
rating = self._gkrating.search(profile).group(1)
games = self._gkgames.search(profile).group(1)
profile = stripHtml(profile)
seen = self._gkseen.search(profile).group(1)
(w, l, d) = self._gkrecord.search(profile).groups()
if profile.find('Team:') >= 0:
team = self._gkteam.search(profile).group(1)
irc.reply(msg, '%s (team %s) is rated %s and has %s active '
'games and a record of W-%s, L-%s, D-%s. ' \
'%s was last seen on Gameknot %s' % \
(name, team, rating, games, w, l, d, name, seen))
else:
irc.reply(msg, '%s is rated %s and has %s active games '
'and a record of W-%s, L-%s, D-%s. ' \
'%s was last seen on Gameknot %s' % \
(name, rating, games, w, l, d, name, seen))
except AttributeError:
if profile.find('User %s not found!' % name) != -1:
irc.error(msg, 'No user %s exists.')
else:
irc.error(msg, 'The format of the page was odd.')
except urllib2.URLError:
irc.error(msg, 'Couldn\'t connect to gameknot.com.')
_zipcode = re.compile(r'Local Forecast for (.*), (.*?) ')
def zipcode(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) = self._zipcode.search(html).groups()
irc.reply(msg, '%s, %s' % (city, state))
except AttributeError:
irc.error(msg, 'the format of the page was odd.')
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 = self._cityregex.search(html).groups()
temp = self._tempregex.search(html).group(1)
conds = self._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.')
_slashdotTime = 0.0
def slashdot(self, irc, msg, args):
"takes no arguments"
if time.time() - self._slashdotTime > 1800:
try:
fd = urllib2.urlopen('http://slashdot.org/slashdot.xml')
slashdotXml = fd.read()
fd.close()
dom = xml.dom.minidom.parseString(slashdotXml)
headlines = []
for headline in dom.getElementsByTagName('title'):
headlines.append(str(headline.firstChild.data))
self._slashdotResponse = ' :: '.join(headlines)
self._slashdotTime = time.time()
except urllib2.URLError, e:
irc.error(msg, str(e))
return
irc.reply(msg, self._slashdotResponse)
Class = Http
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: