fix validate plugin's handling of http-less urls, clean bigassmessage

This commit is contained in:
Ryan Hitchman 2010-03-15 02:31:19 -06:00
parent 0935a72c16
commit 278bc2e13a
2 changed files with 28 additions and 31 deletions

View File

@ -1,7 +1,9 @@
from util import hook
from lxml import etree
import urllib import urllib
from lxml import etree
from util import hook
@hook.command @hook.command
def bam(inp): def bam(inp):
@ -10,25 +12,21 @@ def bam(inp):
if not inp: if not inp:
return bam.__doc__ return bam.__doc__
host = 'http://bigassmessage.com' host = 'http://bigassmessage.com/'
path = '/dsx_BAM/boe.php' path = 'dsx_BAM/boe.php?'
params = {'action': 'saveMsg', 'theStyle': 'basic', 'theMessage': inp} params = {'action': 'saveMsg', 'theStyle': 'basic', 'theMessage': inp}
styles = ['basic', 'magic', 'pepsi', 'jprdy'] if ' ' in inp:
style, message = inp.split(None, 1)
for style in styles: if style in ['basic', 'magic', 'pepsi', 'jprdy']:
if inp.startswith(style + ' '):
params['theStyle'] = style 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)
response = etree.parse(url) status = response.xpath('//status/text()')[0]
status = response.xpath('//status/text()')[0] if status == 'ok':
if status == 'ok': return host + response.xpath('//msgid/text()')[0]
return host + '/' + response.xpath('//msgid/text()')[0] else:
else: return response.xpath('//message/text()')[0]
return response.xpath('//message/text()')[0]
except:
pass

View File

@ -11,9 +11,10 @@ from util import hook
@hook.command('val') @hook.command('val')
@hook.command('valid')
@hook.command @hook.command
def validate(inp): def validate(inp):
'''.val/.validate <url> -- runs url through the w3c markup validator''' '''.val/.valid/.validate <url> -- runs url through w3c markup validator'''
if not inp: if not inp:
return validate.__doc__ return validate.__doc__
@ -21,15 +22,13 @@ def validate(inp):
if not inp.startswith('http://'): if not inp.startswith('http://'):
inp = 'http://' + inp inp = 'http://' + inp
url = 'http://validator.w3.org/check?uri=%s' % urllib.quote(inp, '') url = 'http://validator.w3.org/check?uri=%s' % urllib.quote(inp, '')
info = dict(urllib2.urlopen(url).info()) info = dict(urllib2.urlopen(url).info())
print info print info
status = info['x-w3c-validator-status'].lower() status = info['x-w3c-validator-status'].lower()
if status in ("valid", "invalid"): if status in ("valid", "invalid"):
errorcount = info['x-w3c-validator-errors'] errorcount = info['x-w3c-validator-errors']
warningcount = info['x-w3c-validator-warnings'] warningcount = info['x-w3c-validator-warnings']
return "%s was found to be %s with %s errors and %s warnings." \ return "%s was found to be %s with %s errors and %s warnings." \
" see: %s" % (inp, status, errorcount, warningcount, url) " see: %s" % (inp, status, errorcount, warningcount, url)
else:
return "Something went wrong while validating %s" % inp