mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 11:09:23 +01:00
Adjusted the regex. Added morehelp response. Adjusted the request so that it specifies a browser (site does browser-checking). Used some list comprehension to show only the first 5 results.
This commit is contained in:
parent
50cb2887b2
commit
b1a2b87ed3
@ -246,14 +246,18 @@ class Http(callbacks.Privmsg):
|
|||||||
quote = ' // '.join(quote.splitlines())
|
quote = ' // '.join(quote.splitlines())
|
||||||
irc.reply(msg, quote)
|
irc.reply(msg, quote)
|
||||||
|
|
||||||
_acronymre = re.compile('<td[^>]*><b>[^<]+</b></td>[^<]+<td[^>]*>(\w+)')
|
_acronymre = re.compile('<td[^w]+width="70[^>]+>(<b>|)([^<]+)(</b>|)')
|
||||||
def acronym(self, irc, msg, args):
|
def acronym(self, irc, msg, args):
|
||||||
"""<acronym>"""
|
"""<acronym>
|
||||||
|
|
||||||
|
displays the first 5 acronym matches"""
|
||||||
acronym = privmsgs.getArgs(args)
|
acronym = privmsgs.getArgs(args)
|
||||||
try:
|
try:
|
||||||
url = 'http://www.acronymfinder.com/' \
|
url = 'http://www.acronymfinder.com/' \
|
||||||
'af-query.asp?String=exact&Acronym=%s' % acronym
|
'af-query.asp?String=exact&Acronym=%s' % acronym
|
||||||
fd = urllib2.urlopen(url)
|
request = urllib2.Request(url, headers={'User-agent':
|
||||||
|
'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 4.0)'})
|
||||||
|
fd = urllib2.urlopen(request)
|
||||||
except urllib2.URLError:
|
except urllib2.URLError:
|
||||||
irc.error(msg, 'Couldn\'t connect to acronymfinder.com')
|
irc.error(msg, 'Couldn\'t connect to acronymfinder.com')
|
||||||
return
|
return
|
||||||
@ -263,6 +267,7 @@ class Http(callbacks.Privmsg):
|
|||||||
if len(defs) == 0:
|
if len(defs) == 0:
|
||||||
irc.reply(msg, 'No definitions found.')
|
irc.reply(msg, 'No definitions found.')
|
||||||
else:
|
else:
|
||||||
|
defs=[x[1].strip() for x in defs[1:-1]][:5]
|
||||||
irc.reply(msg, '%s could be %s' % (acronym, ', or '.join(defs)))
|
irc.reply(msg, '%s could be %s' % (acronym, ', or '.join(defs)))
|
||||||
|
|
||||||
Class = Http
|
Class = Http
|
||||||
|
Loading…
Reference in New Issue
Block a user