be permissive with datagov resource file size
[disclosr.git] / admin / validation.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
#http://packages.python.org/CouchDB/client.html
import couchdb
import json
import pprint
import re
from tidylib import tidy_document
 
couch = couchdb.Server('http://192.168.1.113:5984/')
 
# select database
docsdb = couch['disclosr-documents']
 
def f(x):
        invalid = re.compile(r"ensure|testing|flicker|updating|longdesc|Accessibility Checks|not recognized|noscript|audio")
        valid = re.compile(r"line")
        return (not invalid.search(x)) and valid.search(x) and x != ''
 
for row in docsdb.view('app/getValidationRequired'): 
    print row.id
    html = docsdb.get_attachment(row.id,row.value.iterkeys().next()).read()
    #print html
    document, errors = tidy_document(html,options={'accessibility-check':1,'show-warnings':0,'markup':0},keep_doc=True)
    #http://www.aprompt.ca/Tidy/accessibilitychecks.html
    #print document
    errors = '\n'.join(filter(f,errors.split('\n')))
    #print errors
    doc = docsdb.get(row.id)
    doc['validation'] = errors
    docsdb.save(doc)