scary piece of python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def limits(base=None, row=None): | |
if base: | |
row = base.find('table', {'class': 'CLPTable'})\ | |
.find('tr', {'class': 'results-row'}) | |
regex = ur"(.+); (H[0-9]+): (C (≥|>) ([0-9,]+)%|([0-9,]+)% (≤|<|<) C (≤|<|<) ([0-9,]+)%)([ *]*)" | |
else: | |
regex = ur"(.+)(): (C (≥|>) ([0-9,]+)%|([0-9,]+)% (≤|<|<) C (≤|<|<) ([0-9,]+)%)([ *]*)" | |
raw = row.find_all('td', {'rowspan': re.compile('[0-9]+')})[2]\ | |
.findAll(text=True) | |
parsed = [{'category': m.group(1), | |
'code': m.group(2), | |
'low_eq': m.group(5) if m.group(4) and m.group(4) == u'≥' else m.group(6) if m.group(7) and m.group(7) == u'≤' else u'', | |
'low': m.group(5) if m.group(4) and m.group(4) == u'>' else m.group(6) if m.group(7) and m.group(7) != u'≤' else u'', | |
'high_eq': m.group(9) if m.group(9) and m.group(8) == u'≤' else u'', | |
'high': m.group(9) if m.group(9) and m.group(8) != u'≤' else u'', | |
'remark': m.group(10).strip()} | |
if m != None else {'special': s} | |
for (m, s) in | |
((re.match(regex, | |
limit.strip()), | |
limit.strip()) | |
for limit in raw | |
if len(limit.strip()) > 0)] | |
return {'raw': [l.strip() for l in raw if len(l.strip()) > 0], | |
'parsed': parsed} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment