-
Notifications
You must be signed in to change notification settings - Fork 1
/
league_utils.py
45 lines (41 loc) · 1.43 KB
/
league_utils.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
34
35
36
37
38
39
40
41
42
43
44
45
import mwparserfromhell as mw
import util
def convert_league_row_to_task(row, sectionName: str):
skills = []
if 's' in row and row["s"] is not None:
skillCode = mw.parse(row["s"], skip_style_tags=True)
for skillPart in skillCode.filter_templates(matches=lambda t: t.name.matches("SCP")):
if (len(skillPart.params) > 1):
skills.append({
"skill": util.strip(str(skillPart.params[0])),
"level": util.strip(str(skillPart.params[1]))
})
task = {
"name": util.strip(str(row['1'])),
"description": util.strip(str(row.get('2'))),
"skills": skills,
"other": util.strip(str(row["other"])) if "other" in row else "",
"tier": util.strip(sectionName)
}
return task
# use this one for leagues 4 and newer
def convert_league_row_to_task_new(row):
skills = []
if 's' in row and row["s"] is not None:
skillCode = mw.parse(row["s"], skip_style_tags=True)
for skillPart in skillCode.filter_templates(matches=lambda t: t.name.matches("SCP")):
if (len(skillPart.params) > 1):
skills.append({
"skill": util.strip(str(skillPart.params[0])),
"level": util.strip(str(skillPart.params[1]))
})
task = {
"id": util.strip(str(row["id"])),
"name": util.strip(str(row['1'])),
"description": util.strip(str(row.get('2'))),
"skills": skills,
"other": util.strip(str(row["other"])) if "other" in row else "",
"tier": util.strip(str(row["tier"]).capitalize()),
"area": util.strip(str(row["region"]))
}
return task