Skip to content

Commit 720feed

Browse files
authored
Merge pull request #52 from cuappdev/claire/basketballScoreBreakdown
Fix #49 for basketball score breakdowns
2 parents 59175e0 + 485b426 commit 720feed

1 file changed

Lines changed: 36 additions & 1 deletion

File tree

src/scrapers/game_details_scrape.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ def extract_teams_and_scores(box_score_section, sport):
4343
team_name = team_name_cell.text.strip().replace("Winner", "").strip() if team_name_cell else "Unknown"
4444
scores = [td.text.strip() for td in row.find_all(TAG_TD)[1:]]
4545

46+
# Basketball box score includes a "Records" column at the end - exclude it
47+
if sport == 'basketball' and scores:
48+
scores = scores[:-1]
49+
4650
team_name = ' '.join(team_name.split())
4751
team_names.append(team_name)
4852
period_scores.append(scores)
@@ -63,7 +67,7 @@ def soccer_summary(box_score_section):
6367
event = row.find_all(TAG_TD)[2]
6468
desc = event.find_all(TAG_SPAN)[-1].text.strip()
6569

66-
if team == "COR" or team == "CU":
70+
if team == "COR" or team == "CU" or team == "CRNL":
6771
cornell_score += 1
6872
else:
6973
opp_score += 1
@@ -224,6 +228,36 @@ def baseball_summary(box_score_section):
224228
summary = [{"message": "No scoring events in this game."}]
225229
return summary
226230

231+
# def basketball_summary(box_score_section):
232+
# summary = []
233+
# scoring_section = box_score_section.find(TAG_SECTION, {ATTR_ARIA_LABEL: LABEL_SCORING_SUMMARY})
234+
# if scoring_section:
235+
# scoring_rows = scoring_section.find(TAG_TBODY)
236+
# if scoring_rows:
237+
# cornell_score = 0
238+
# opp_score = 0
239+
# for row in scoring_rows.find_all(TAG_TR):
240+
# time = row.find_all(TAG_TD)[0].text.strip()
241+
# team = row.find_all(TAG_TD)[1].find(TAG_IMG)[ATTR_ALT]
242+
# event = row.find_all(TAG_TD)[2]
243+
# desc = event.find_all(TAG_SPAN)[-1].text.strip()
244+
245+
# if team == "COR" or team == "CU" or team == "CRNL":
246+
# cornell_score += 1
247+
# else:
248+
# opp_score += 1
249+
250+
# summary.append({
251+
# 'time': time,
252+
# 'team': team,
253+
# 'description': desc,
254+
# 'cor_score': cornell_score,
255+
# 'opp_score': opp_score
256+
# })
257+
# if not summary:
258+
# summary = [{"message": "No scoring events in this game."}]
259+
# return summary
260+
227261
def scrape_game(url, sport):
228262
soup = fetch_page(url)
229263
box_score_section = soup.find(class_=CLASS_BOX_SCORE) if sport in ['baseball', 'softball'] else soup.find(id=ID_BOX_SCORE)
@@ -237,6 +271,7 @@ def scrape_game(url, sport):
237271
'field hockey': (lambda: extract_teams_and_scores(box_score_section, 'field hockey'), field_hockey_summary),
238272
'lacrosse': (lambda: extract_teams_and_scores(box_score_section, 'lacrosse'), lacrosse_summary),
239273
'baseball': (lambda: extract_teams_and_scores(box_score_section, 'baseball'), baseball_summary),
274+
'basketball': (lambda: extract_teams_and_scores(box_score_section, 'basketball'), lambda _: []),
240275
}
241276

242277
extract_teams_func, summary_func = sport_parsers.get(sport, (None, None))

0 commit comments

Comments
 (0)