-
Notifications
You must be signed in to change notification settings - Fork 2
/
html_validate.py
33 lines (25 loc) · 985 Bytes
/
html_validate.py
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
from HelperFunctions import getLogger
import requests
localLogger = getLogger()
def getDynamicLogger(messageType):
if messageType == "error":
return localLogger.error
elif messageType == "warning":
return localLogger.warning
else:
return localLogger.info
def validateAndLog(data):
r = requests.post('https://validator.w3.org/nu/',
data=data, params={'out': 'json'},
headers={'Content-Type': 'text/html; charset=UTF-8'})
messages = r.json()["messages"]
for message in messages:
log = getDynamicLogger(str(message["type"]))
log("Type: " + str(message["type"]))
log("Line: " + str(message["lastLine"]))
try:
log("Start Column: " + str(message["firstColumn"]))
log("End Column: " + str(message["lastColumn"]))
except KeyError:
pass
log("Message: " + str(message["message"]) + "\n")