This repository has been archived on 2023-04-13. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
CloudBot/disabled_stuff/validate.py

27 lines
750 B
Python
Raw Permalink Normal View History

2013-09-04 18:30:04 +08:00
"""
2011-11-20 22:23:31 +13:00
Runs a given url through the w3c validator
by Vladi
2013-09-04 18:30:04 +08:00
"""
2011-11-20 22:23:31 +13:00
from util import hook, http
2012-02-28 22:09:19 -08:00
@hook.command('w3c')
2011-11-20 22:23:31 +13:00
@hook.command
def validate(inp):
2013-09-04 18:30:04 +08:00
"""validate <url> -- Runs url through the w3c markup validator."""
2011-11-20 22:23:31 +13:00
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"):
error_count = info['x-w3c-validator-errors']
warning_count = info['x-w3c-validator-warnings']
return "{} was found to be {} with {} errors and {} warnings." \
" see: {}".format(inp, status, error_count, warning_count, url)