From 278bc2e13ace6435f6e92ae63de6b4f419d7715d Mon Sep 17 00:00:00 2001 From: Ryan Hitchman Date: Mon, 15 Mar 2010 02:31:19 -0600 Subject: [PATCH] fix validate plugin's handling of http-less urls, clean bigassmessage --- plugins/bigassmessage.py | 36 +++++++++++++++++------------------- plugins/validate.py | 23 +++++++++++------------ 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/plugins/bigassmessage.py b/plugins/bigassmessage.py index eec582a..921b985 100644 --- a/plugins/bigassmessage.py +++ b/plugins/bigassmessage.py @@ -1,7 +1,9 @@ -from util import hook -from lxml import etree import urllib +from lxml import etree + +from util import hook + @hook.command def bam(inp): @@ -10,25 +12,21 @@ def bam(inp): if not inp: return bam.__doc__ - host = 'http://bigassmessage.com' - path = '/dsx_BAM/boe.php' + host = 'http://bigassmessage.com/' + path = 'dsx_BAM/boe.php?' params = {'action': 'saveMsg', 'theStyle': 'basic', 'theMessage': inp} - styles = ['basic', 'magic', 'pepsi', 'jprdy'] - - for style in styles: - if inp.startswith(style + ' '): + if ' ' in inp: + style, message = inp.split(None, 1) + if style in ['basic', 'magic', 'pepsi', 'jprdy']: params['theStyle'] = style - params['theMessage'] = inp[len(style) + 1:] + params['theMessage'] = message - url = host + path + '?' + urllib.urlencode(params) + url = host + path + urllib.urlencode(params) - try: - response = etree.parse(url) - status = response.xpath('//status/text()')[0] - if status == 'ok': - return host + '/' + response.xpath('//msgid/text()')[0] - else: - return response.xpath('//message/text()')[0] - except: - pass + response = etree.parse(url) + status = response.xpath('//status/text()')[0] + if status == 'ok': + return host + response.xpath('//msgid/text()')[0] + else: + return response.xpath('//message/text()')[0] diff --git a/plugins/validate.py b/plugins/validate.py index f61d1ca..fb8dae2 100644 --- a/plugins/validate.py +++ b/plugins/validate.py @@ -11,9 +11,10 @@ from util import hook @hook.command('val') +@hook.command('valid') @hook.command def validate(inp): - '''.val/.validate -- runs url through the w3c markup validator''' + '''.val/.valid/.validate -- runs url through w3c markup validator''' if not inp: return validate.__doc__ @@ -21,15 +22,13 @@ def validate(inp): if not inp.startswith('http://'): inp = 'http://' + inp - url = 'http://validator.w3.org/check?uri=%s' % urllib.quote(inp, '') - info = dict(urllib2.urlopen(url).info()) + url = 'http://validator.w3.org/check?uri=%s' % urllib.quote(inp, '') + info = dict(urllib2.urlopen(url).info()) - print info - status = info['x-w3c-validator-status'].lower() - if status in ("valid", "invalid"): - errorcount = info['x-w3c-validator-errors'] - warningcount = info['x-w3c-validator-warnings'] - return "%s was found to be %s with %s errors and %s warnings." \ - " see: %s" % (inp, status, errorcount, warningcount, url) - else: - return "Something went wrong while validating %s" % inp + print info + status = info['x-w3c-validator-status'].lower() + if status in ("valid", "invalid"): + errorcount = info['x-w3c-validator-errors'] + warningcount = info['x-w3c-validator-warnings'] + return "%s was found to be %s with %s errors and %s warnings." \ + " see: %s" % (inp, status, errorcount, warningcount, url)