This repository has been archived on 2023-04-13. You can view files and clone it, but cannot push or open issues or pull requests.
CloudBot/plugins/validate.py
2012-02-28 10:41:53 +08:00

26 lines
719 B
Python

'''
Runs a given url through the w3c validator
by Vladi
'''
from util import hook, http
@hook.command
def validate(inp):
".validate <url> -- Runs url through the w3c markup validator."
if not inp.startswith('http://'):
inp = 'http://' + inp
url = 'http://validator.w3.org/check?uri=' + http.quote_plus(inp)
info = dict(http.open(url).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)