blob: a94af5000bbf1c26000f8302f10e4ffe3f393656 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
from __future__ import print_function
import sys
import httplib2
import time
import config
import urllist
# TODO: spawn server here
BASEURL="http://localhost:8000/"
#def print_browserlog(url):
# driver = webdriver.Firefox()
# driver.get(url)
# body = driver.find_element_by_tag_name("body")
# body.send_keys(Keys.CONTROL + 't')
# for i in driver.get_log('browser'):
# print(i)
# driver.close()
# TODO: turn to a test
def validate_html(url):
h = httplib2.Http(".cache")
# TODO: the w3c-validator must be a configurable setting
urlrequest = "http://icarus.local/w3c-validator/check?doctype=HTML5&uri="+url
try:
resp, content = h.request(urlrequest, "HEAD")
if resp['x-w3c-validator-status'] == "Abort":
config.logger.error("FAILed call %s" % url)
else:
config.logger.error("url %s is %s\terrors %s warnings %s (check at %s)" % (url, resp['x-w3c-validator-status'], resp['x-w3c-validator-errors'], resp['x-w3c-validator-warnings'], urlrequest))
except Exception as e:
config.logger.warn("Failed validation call: %s" % e.__str__())
print("done %s" % url)
if __name__ == "__main__":
if len(sys.argv) > 1:
validate_html(sys.argv[1])
else:
for url in urllist.URLS:
validate_html(BASEURL+url)
|