mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-20 09:29:24 +01:00
Added acronym and geekquote commands and triple-quoted method docstrings.
This commit is contained in:
parent
958d1c934e
commit
fa261c0e80
@ -49,6 +49,7 @@ import time
|
|||||||
import urllib
|
import urllib
|
||||||
import urllib2
|
import urllib2
|
||||||
import threading
|
import threading
|
||||||
|
import htmlentitydefs
|
||||||
import xml.dom.minidom
|
import xml.dom.minidom
|
||||||
|
|
||||||
import debug
|
import debug
|
||||||
@ -70,7 +71,7 @@ class Http(callbacks.Privmsg):
|
|||||||
_fmPopular=re.compile('<popularity_percent>([^<]+)</popularity_percent>')
|
_fmPopular=re.compile('<popularity_percent>([^<]+)</popularity_percent>')
|
||||||
_fmLastUpdated = re.compile('<date_updated>([^<]+)</date_updated>')
|
_fmLastUpdated = re.compile('<date_updated>([^<]+)</date_updated>')
|
||||||
def freshmeat(self, irc, msg, args):
|
def freshmeat(self, irc, msg, args):
|
||||||
"<project name>"
|
"""<project name>"""
|
||||||
project = privmsgs.getArgs(args)
|
project = privmsgs.getArgs(args)
|
||||||
url = 'http://www.freshmeat.net/projects-xml/%s' % project
|
url = 'http://www.freshmeat.net/projects-xml/%s' % project
|
||||||
try:
|
try:
|
||||||
@ -95,7 +96,7 @@ class Http(callbacks.Privmsg):
|
|||||||
irc.reply(msg, debug.exnToString(e))
|
irc.reply(msg, debug.exnToString(e))
|
||||||
|
|
||||||
def stockquote(self, irc, msg, args):
|
def stockquote(self, irc, msg, args):
|
||||||
"<company symbol>"
|
"""<company symbol>"""
|
||||||
symbol = privmsgs.getArgs(args)
|
symbol = privmsgs.getArgs(args)
|
||||||
url = 'http://finance.yahoo.com/d/quotes.csv?s=%s'\
|
url = 'http://finance.yahoo.com/d/quotes.csv?s=%s'\
|
||||||
'&f=sl1d1t1c1ohgv&e=.csv' % symbol
|
'&f=sl1d1t1c1ohgv&e=.csv' % symbol
|
||||||
@ -120,7 +121,7 @@ class Http(callbacks.Privmsg):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def foldoc(self, irc, msg, args):
|
def foldoc(self, irc, msg, args):
|
||||||
"<something to lookup on foldoc>"
|
"""<something to lookup on foldoc>"""
|
||||||
search = '+'.join([urllib.quote(arg) for arg in args])
|
search = '+'.join([urllib.quote(arg) for arg in args])
|
||||||
url = 'http://foldoc.doc.ic.ac.uk/foldoc/foldoc.cgi?query=%s' % search
|
url = 'http://foldoc.doc.ic.ac.uk/foldoc/foldoc.cgi?query=%s' % search
|
||||||
try:
|
try:
|
||||||
@ -142,7 +143,7 @@ class Http(callbacks.Privmsg):
|
|||||||
_gkteam = re.compile('Team:([^\s]+)')
|
_gkteam = re.compile('Team:([^\s]+)')
|
||||||
_gkseen = re.compile('seen on GK: ([^\n]+)')
|
_gkseen = re.compile('seen on GK: ([^\n]+)')
|
||||||
def gkstats(self, irc, msg, args):
|
def gkstats(self, irc, msg, args):
|
||||||
"<name>"
|
"""<name>"""
|
||||||
name = privmsgs.getArgs(args)
|
name = privmsgs.getArgs(args)
|
||||||
gkprofile = 'http://www.gameknot.com/stats.pl?%s' % name
|
gkprofile = 'http://www.gameknot.com/stats.pl?%s' % name
|
||||||
try:
|
try:
|
||||||
@ -175,7 +176,7 @@ class Http(callbacks.Privmsg):
|
|||||||
|
|
||||||
_zipcode = re.compile(r'Local Forecast for (.*), (.*?) ')
|
_zipcode = re.compile(r'Local Forecast for (.*), (.*?) ')
|
||||||
def zipcode(self, irc, msg, args):
|
def zipcode(self, irc, msg, args):
|
||||||
"<US zip code>"
|
"""<US zip code>"""
|
||||||
zip = privmsgs.getArgs(args)
|
zip = privmsgs.getArgs(args)
|
||||||
url = "http://www.weather.com/weather/local/%s?lswe=%s" % (zip, zip)
|
url = "http://www.weather.com/weather/local/%s?lswe=%s" % (zip, zip)
|
||||||
try:
|
try:
|
||||||
@ -194,7 +195,7 @@ class Http(callbacks.Privmsg):
|
|||||||
_condregex = re.compile('CLASS=obsInfo2><b CLASS=obsTextA>(.*)</b></td>',\
|
_condregex = re.compile('CLASS=obsInfo2><b CLASS=obsTextA>(.*)</b></td>',\
|
||||||
re.IGNORECASE)
|
re.IGNORECASE)
|
||||||
def weather(self, irc, msg, args):
|
def weather(self, irc, msg, args):
|
||||||
"<US zip code>"
|
"""<US zip code>"""
|
||||||
zip = privmsgs.getArgs(args)
|
zip = privmsgs.getArgs(args)
|
||||||
url = "http://www.weather.com/weather/local/%s?lswe=%s" % (zip, zip)
|
url = "http://www.weather.com/weather/local/%s?lswe=%s" % (zip, zip)
|
||||||
try:
|
try:
|
||||||
@ -211,7 +212,7 @@ class Http(callbacks.Privmsg):
|
|||||||
|
|
||||||
_slashdotTime = 0.0
|
_slashdotTime = 0.0
|
||||||
def slashdot(self, irc, msg, args):
|
def slashdot(self, irc, msg, args):
|
||||||
"takes no arguments"
|
"""takes no arguments"""
|
||||||
if time.time() - self._slashdotTime > 1800:
|
if time.time() - self._slashdotTime > 1800:
|
||||||
try:
|
try:
|
||||||
fd = urllib2.urlopen('http://slashdot.org/slashdot.xml')
|
fd = urllib2.urlopen('http://slashdot.org/slashdot.xml')
|
||||||
@ -228,6 +229,48 @@ class Http(callbacks.Privmsg):
|
|||||||
return
|
return
|
||||||
irc.reply(msg, self._slashdotResponse)
|
irc.reply(msg, self._slashdotResponse)
|
||||||
|
|
||||||
|
_geekquotere = re.compile('<p class="qt">(.*?)</p>')
|
||||||
|
def geekquote(self, irc, msg, args):
|
||||||
|
"[<multiline>]"
|
||||||
|
multiline = privmsgs.getArgs(args, needed=0, optional=1)
|
||||||
|
try:
|
||||||
|
fd = urllib2.urlopen('http://bash.org/?random1')
|
||||||
|
except urllib2.URLError:
|
||||||
|
irc.error(msg, 'Error connecting to geekquote server.')
|
||||||
|
return
|
||||||
|
html = fd.read()
|
||||||
|
fd.close()
|
||||||
|
if multiline:
|
||||||
|
m = self._geekquotere.search(html, re.M)
|
||||||
|
else:
|
||||||
|
m = self._geekquotere.search(html)
|
||||||
|
if m is None:
|
||||||
|
irc.error(msg, 'No quote found.')
|
||||||
|
return
|
||||||
|
quote = m.group(1)
|
||||||
|
quote = ' // '.join(quote.splitlines())
|
||||||
|
for (def, replacement) in htmlentitydefs.entitydefs.iteritems():
|
||||||
|
quote = quote.replace(def, replacement)
|
||||||
|
irc.reply(msg, quote)
|
||||||
|
|
||||||
|
_acronymre = re.compile('<td[^>]*><b>[^<]+</b></td>[^<]+<td[^>]*>(\w+)')
|
||||||
|
def acronym(self, irc, msg, args):
|
||||||
|
"""<acronym>"""
|
||||||
|
acronym = privmsgs.getArgs(args)
|
||||||
|
try:
|
||||||
|
url = 'http://www.acronymfinder.com/' \
|
||||||
|
'af-query.asp?String=exact&Acronym=%s' % acronym
|
||||||
|
fd = urllib2.urlopen(url)
|
||||||
|
except urllib2.URLError:
|
||||||
|
irc.error(msg, 'Couldn\'t connect to acronymfinder.com')
|
||||||
|
return
|
||||||
|
html = fd.read()
|
||||||
|
fd.close()
|
||||||
|
defs = self._acronymre.findall(html)
|
||||||
|
if len(defs) == 0:
|
||||||
|
irc.reply(msg, 'No definitions found.')
|
||||||
|
else:
|
||||||
|
irc.reply(msg, '%s could be %s' % (acronym, ', or '.join(defs)))
|
||||||
|
|
||||||
Class = Http
|
Class = Http
|
||||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
Loading…
Reference in New Issue
Block a user