forked from kyleconroy/circle-of-parity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parity.py
58 lines (43 loc) · 1.28 KB
/
parity.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
46
47
48
49
50
51
52
53
54
def parse_conferences(conference_file, year):
conferences = []
current_conference = {}
for line in conference_file:
if line.startswith(" "):
if current_conference:
team = line.strip().replace('"', "")
current_conference["teams"].append(team)
elif line.startswith(" "):
current_conference = {
"name": line.strip(),
"teams": [],
}
conferences.append(current_conference)
return {
"year": year,
"conferences": conferences,
}
def parse_scores(score_file):
scores = []
for line in score_file:
line = line.replace("Institute1", "Institute ")
parts = line.split()
if not len(parts):
continue
city = None
state = None
row = [parts.pop(0)]
team = []
score_count = 0
for part in parts:
if score_count > 2:
break
try:
score = int(part)
row.append(" ".join(team))
row.append(score)
score_count += 1
team = []
except ValueError:
team.append(part)
scores.append(row)
return scores