- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_parser.py
More file actions
Latest commit
41 lines (35 loc) · 1.56 KB
/
Copy pathtest_parser.py
File metadata and controls
41 lines (35 loc) · 1.56 KB
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
importre, htmlashtml_module
withopen('debug_orioles_program.html', encoding='utf-8', errors='replace') asf:
body=f.read()
blocks=re.findall(
r"mlb26-program-accordion-sub[\"'][^>]*>.*?</div>\s*</div>\s*</div>\s*</div>",
body, re.DOTALL|re.IGNORECASE
)
print(f'Found {len(blocks)} accordion-sub blocks')
forblkinblocks:
m_title=re.search(
r"class=[\"'][^\"']*accordion-toggle-label[^\"']*[\"'][^>]*>\s*(.*?)\s*</span>",
blk, re.DOTALL|re.IGNORECASE
)
title=html_module.unescape(re.sub(r'<[^>]+>', '', m_title.group(1))).strip() ifm_titleelse''
m_meter=re.search(r"<meter[^>]+max=['\"](\d+)['\"][^>]+value=['\"](\d+)['\"]", blk, re.IGNORECASE)
ifnotm_meter:
m_meter=re.search(r"<meter[^>]+value=['\"](\d+)['\"][^>]+max=['\"](\d+)['\"]", blk, re.IGNORECASE)
ifm_meter:
cur_val, max_val=m_meter.group(1), m_meter.group(2)
else:
cur_val, max_val='0', '0'
else:
max_val, cur_val=m_meter.group(1), m_meter.group(2)
m_rnum=re.search(r"class=['\"]reward['\"][^>]*>(.*?)</div>", blk, re.DOTALL)
reward=''
ifm_rnum:
r_text=html_module.unescape(re.sub(r'<[^>]+>', ' ', m_rnum.group(1))).strip()
mn=re.search(r'([\d,]+)', r_text)
ifmn:
reward=mn.group(1).replace(',','') +' XP'
try:
pct=min(100.0, round(int(cur_val)/int(max_val)*100,1)) ifint(max_val)>0else0.0
except:
pct=0.0
print(f' [{pct:5.1f}%] {title[:50]!s:<50} | prog={cur_val}/{max_val} | reward={reward}')