37 lines
1.3 KiB
Python
37 lines
1.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
import io, re, sys
|
|
|
|
def find_oj_section(html, start):
|
|
n = len(html)
|
|
depth = 1
|
|
i = start + len('<div class="oj-section"')
|
|
while depth > 0 and i < n:
|
|
o = html.find('<div', i)
|
|
c = html.find('</div>', i)
|
|
if c == -1:
|
|
return -1
|
|
if o != -1 and o < c:
|
|
depth += 1
|
|
i = o + 4
|
|
else:
|
|
depth -= 1
|
|
i = c + 6
|
|
return i
|
|
|
|
for f in sys.argv[1:]:
|
|
c = io.open(f, encoding='utf-8').read()
|
|
pat = re.compile(r'<div class="oj-section" data-oj-section="([^"]+)">')
|
|
print('===', f.replace('\\', '/').split('/')[-1])
|
|
for m in pat.finditer(c):
|
|
name = m.group(1)
|
|
end = find_oj_section(c, m.start())
|
|
blk = c[m.start():end]
|
|
expl = blk.count('class="oj-explains"')
|
|
full = blk.count('class="prob-detail" onclick')
|
|
hw = blk.count('class="prob-detail homework"')
|
|
mark = 'OK' if (expl == 1 and full + hw == 5) else 'BAD'
|
|
print(' %-4s expl=%d full=%d homework=%d %s' % (name, expl, full, hw, mark))
|
|
print(' total homework-note count:', c.count('未提交 · 课后作业'))
|
|
print(' div balance:', c.count('<div'), '/', c.count('</div>'),
|
|
'OK' if c.count('<div') == c.count('</div>') else 'MISMATCH')
|