Skip to content

Commit 92c1425

Browse files
Merge pull request #32 from cuappdev/ice-hockey-fix
Fix ice hockey scores
2 parents cd1949f + 0719e44 commit 92c1425

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

src/scrapers/game_details_scrape.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,27 @@ def hockey_summary(box_score_section):
8888
if scoring_table:
8989
scoring_rows = scoring_table.find(TAG_TBODY)
9090
if scoring_rows:
91+
cornell_score = 0
92+
opp_score = 0
9193
for row in scoring_rows.find_all(TAG_TR):
9294
team = row.find_all(TAG_TD)[1].find(TAG_IMG)[ATTR_ALT]
9395
period = row.find_all(TAG_TD)[2].text.strip()
9496
time = row.find_all(TAG_TD)[3].text.strip()
9597
scorer = row.find_all(TAG_TD)[4].text.strip()
9698
assist = row.find_all(TAG_TD)[5].text.strip()
97-
opp_score = row.find_all(TAG_TD)[6].text.strip()
98-
cor_score = row.find_all(TAG_TD)[7].text.strip()
99+
100+
if team == "COR" or team == "CU" or team == "Cornell":
101+
cornell_score += 1
102+
else:
103+
opp_score += 1
104+
99105
summary.append({
100106
'team': team,
101107
'period': period,
102108
'time': time,
103109
'scorer': scorer,
104110
'assist': assist,
105-
'cor_score': cor_score,
111+
'cor_score': cornell_score,
106112
'opp_score': opp_score,
107113
})
108114
if not summary:

src/scrapers/games_scraper.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,6 @@ def parse_schedule_page(url, sport, gender):
149149
for event in game_data["box_score"]:
150150
if "cor_score" in event and "opp_score" in event:
151151
event["cor_score"], event["opp_score"] = event["opp_score"], event["cor_score"]
152-
153-
if sport == "Ice Hockey":
154-
location_data = game_data["location"].split("\n") if game_data["location"] else [""]
155-
geo_location = location_data[0]
156-
is_home_game = "Ithaca" in geo_location
157-
158-
if not is_home_game and game_data["box_score"]:
159-
for event in game_data["box_score"]:
160-
if "cor_score" in event and "opp_score" in event:
161-
event["cor_score"], event["opp_score"] = event["opp_score"], event["cor_score"]
162152

163153
else:
164154
game_data["box_score"] = None
@@ -220,6 +210,27 @@ def process_game_data(game_data):
220210
if game_data["score_breakdown"] and is_home_game:
221211
game_data["score_breakdown"] = game_data["score_breakdown"][::-1]
222212

213+
# consistency check for ice hockey, since can be randomly ordered
214+
if game_data["sport"] == "Ice Hockey" and game_data["score_breakdown"] and game_data["box_score"]:
215+
# Get final scores from box score
216+
final_box_cor_score = None
217+
final_box_opp_score = None
218+
for event in reversed(game_data["box_score"]):
219+
if "cor_score" in event and "opp_score" in event:
220+
final_box_cor_score = event["cor_score"]
221+
final_box_opp_score = event["opp_score"]
222+
break
223+
224+
# Compare with score breakdown
225+
if final_box_cor_score and len(game_data["score_breakdown"]) >= 2:
226+
cor_final = game_data["score_breakdown"][0][-1]
227+
opp_final = game_data["score_breakdown"][1][-1]
228+
229+
# If they don't match, flip the arrays
230+
if str(final_box_cor_score) != str(cor_final) or str(final_box_opp_score) != str(opp_final):
231+
print("flipping")
232+
game_data["score_breakdown"] = game_data["score_breakdown"][::-1]
233+
223234
# finds any existing game with the same key fields regardless of time
224235
curr_game = GameService.get_game_by_key_fields(
225236
city,

0 commit comments

Comments
 (0)