From b1a2b87ed3f07d785ed97d893435896f20eb540e Mon Sep 17 00:00:00 2001 From: James Vega Date: Mon, 31 Mar 2003 03:26:23 +0000 Subject: [PATCH] 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. --- plugins/Http.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/plugins/Http.py b/plugins/Http.py index b24751480..562087235 100644 --- a/plugins/Http.py +++ b/plugins/Http.py @@ -246,14 +246,18 @@ class Http(callbacks.Privmsg): quote = ' // '.join(quote.splitlines()) irc.reply(msg, quote) - _acronymre = re.compile(']*>[^<]+[^<]+]*>(\w+)') + _acronymre = re.compile(']+>(|)([^<]+)(|)') def acronym(self, irc, msg, args): - """""" + """ + + displays the first 5 acronym matches""" acronym = privmsgs.getArgs(args) try: url = 'http://www.acronymfinder.com/' \ '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: irc.error(msg, 'Couldn\'t connect to acronymfinder.com') return @@ -263,6 +267,7 @@ class Http(callbacks.Privmsg): if len(defs) == 0: irc.reply(msg, 'No definitions found.') else: + defs=[x[1].strip() for x in defs[1:-1]][:5] irc.reply(msg, '%s could be %s' % (acronym, ', or '.join(defs))) Class = Http