mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 13:19:24 +01:00
Added title command; fixed a latent bug or two.
This commit is contained in:
parent
b037bcda4b
commit
45cdde675c
@ -58,6 +58,25 @@ class FreshmeatException(Exception):
|
|||||||
|
|
||||||
class Http(callbacks.Privmsg):
|
class Http(callbacks.Privmsg):
|
||||||
threaded = True
|
threaded = True
|
||||||
|
|
||||||
|
_titleRe = re.compile(r'<title>(.*)</title>')
|
||||||
|
def title(self, irc, msg, args):
|
||||||
|
"""<url>
|
||||||
|
|
||||||
|
Returns the HTML <title>...</title> of a URL.
|
||||||
|
"""
|
||||||
|
url = privmsgs.getArgs(args)
|
||||||
|
try:
|
||||||
|
fd = urllib2.urlopen(url)
|
||||||
|
text = fd.read()
|
||||||
|
m = self._titleRe.search(text)
|
||||||
|
if m is not None:
|
||||||
|
irc.reply(msg, m.group(1))
|
||||||
|
else:
|
||||||
|
irc.reply(msg, 'That URL appears to have no HTML title.')
|
||||||
|
except Exception, e:
|
||||||
|
irc.error(msg, debug.exnToString(e))
|
||||||
|
|
||||||
_fmProject = re.compile('<projectname_full>([^<]+)</projectname_full>')
|
_fmProject = re.compile('<projectname_full>([^<]+)</projectname_full>')
|
||||||
_fmVersion = re.compile('<latest_version>([^<]+)</latest_version>')
|
_fmVersion = re.compile('<latest_version>([^<]+)</latest_version>')
|
||||||
_fmVitality = re.compile('<vitality_percent>([^<]+)</vitality_percent>')
|
_fmVitality = re.compile('<vitality_percent>([^<]+)</vitality_percent>')
|
||||||
@ -86,10 +105,10 @@ class Http(callbacks.Privmsg):
|
|||||||
'and a popularity of %s, is in version %s.' % \
|
'and a popularity of %s, is in version %s.' % \
|
||||||
(project, lastupdated, vitality, popularity, version))
|
(project, lastupdated, vitality, popularity, version))
|
||||||
except FreshmeatException, e:
|
except FreshmeatException, e:
|
||||||
irc.reply(msg, debug.exnToString(e))
|
irc.error(msg, debug.exnToString(e))
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
debug.recoverableException()
|
debug.recoverableException()
|
||||||
irc.reply(msg, debug.exnToString(e))
|
irc.error(msg, debug.exnToString(e))
|
||||||
|
|
||||||
def stockquote(self, irc, msg, args):
|
def stockquote(self, irc, msg, args):
|
||||||
"""<company symbol>
|
"""<company symbol>
|
||||||
@ -105,7 +124,7 @@ class Http(callbacks.Privmsg):
|
|||||||
quote = fd.read()
|
quote = fd.read()
|
||||||
fd.close()
|
fd.close()
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
irc.reply(msg, debug.exnToString(e))
|
irc.error(msg, debug.exnToString(e))
|
||||||
return
|
return
|
||||||
data = quote.split(',')
|
data = quote.split(',')
|
||||||
#debug.printf(data) # debugging
|
#debug.printf(data) # debugging
|
||||||
@ -139,6 +158,7 @@ class Http(callbacks.Privmsg):
|
|||||||
fd.close()
|
fd.close()
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
irc.error(msg, debug.exnToString(e))
|
irc.error(msg, debug.exnToString(e))
|
||||||
|
return
|
||||||
text = html.split('<P>\n', 2)[1]
|
text = html.split('<P>\n', 2)[1]
|
||||||
text = text.replace('.\n', '. ')
|
text = text.replace('.\n', '. ')
|
||||||
text = text.replace('\n', ' ')
|
text = text.replace('\n', ' ')
|
||||||
|
Loading…
Reference in New Issue
Block a user