|
|
|
|
@@ -291,7 +291,6 @@ def main(
|
|
|
|
|
def match_opponent(text: str) -> Optional[TeamRec]:
|
|
|
|
|
return best_match_team(text, by_slug, by_norm)
|
|
|
|
|
|
|
|
|
|
# Group by game_id if available; otherwise fallback on (date + unordered pair + raw score text if present)
|
|
|
|
|
buckets: Dict[str, dict] = {}
|
|
|
|
|
fallback_rows = 0
|
|
|
|
|
|
|
|
|
|
@@ -336,7 +335,6 @@ def main(
|
|
|
|
|
if fallback_rows:
|
|
|
|
|
logging.info(f"Used fallback dedupe for {fallback_rows} rows without game_id.")
|
|
|
|
|
|
|
|
|
|
# Merge perspectives into a single home/away row
|
|
|
|
|
out_rows = []
|
|
|
|
|
time_cache: Dict[str, Optional[str]] = {}
|
|
|
|
|
|
|
|
|
|
@@ -345,11 +343,9 @@ def main(
|
|
|
|
|
date = p[0]["date"]
|
|
|
|
|
game_id = bucket.get("game_id", "")
|
|
|
|
|
|
|
|
|
|
# Identify home/away perspectives
|
|
|
|
|
p_home = next((x for x in p if x["is_away"] is False), None)
|
|
|
|
|
p_away = next((x for x in p if x["is_away"] is True), None)
|
|
|
|
|
|
|
|
|
|
# Team identities
|
|
|
|
|
home_team = (p_home["team"] if p_home else (p_away["opp"] if p_away else None))
|
|
|
|
|
away_team = (p_away["team"] if p_away else (p_home["opp"] if p_home else None))
|
|
|
|
|
|
|
|
|
|
@@ -358,7 +354,6 @@ def main(
|
|
|
|
|
return rec.slug, rec.instance_id, rec.team_id, rec.name
|
|
|
|
|
return fallback_slug, "", "", fallback_slug.replace("-", " ").title()
|
|
|
|
|
|
|
|
|
|
# Prefer runs from the explicit perspective (home if available; otherwise away)
|
|
|
|
|
home_runs = away_runs = None
|
|
|
|
|
if p_home and isinstance(p_home["team_runs"], int) and isinstance(p_home["opp_runs"], int):
|
|
|
|
|
home_runs = p_home["team_runs"]
|
|
|
|
|
@@ -367,7 +362,6 @@ def main(
|
|
|
|
|
away_runs = p_away["team_runs"]
|
|
|
|
|
home_runs = p_away["opp_runs"]
|
|
|
|
|
|
|
|
|
|
# Fallback: single perspective present but numbers known → place by is_away
|
|
|
|
|
if (home_runs is None or away_runs is None) and p:
|
|
|
|
|
one = p[0]
|
|
|
|
|
if isinstance(one["team_runs"], int) and isinstance(one["opp_runs"], int):
|
|
|
|
|
@@ -378,7 +372,6 @@ def main(
|
|
|
|
|
home_runs = one["team_runs"]; away_runs = one["opp_runs"]
|
|
|
|
|
home_team = one["team"]; away_team = one["opp"] if one["opp"] else away_team
|
|
|
|
|
|
|
|
|
|
# Pack final team identifiers (fallback slug = guess from perspectives)
|
|
|
|
|
guess_home_fallback = (p_home["team"].slug if p_home and p_home["team"] else
|
|
|
|
|
p_away["opp"].slug if p_away and p_away["opp"] else
|
|
|
|
|
p[0]["pair"][0])
|
|
|
|
|
@@ -389,7 +382,6 @@ def main(
|
|
|
|
|
home_slug, home_inst, home_id, home_name = pack_team(home_team, guess_home_fallback)
|
|
|
|
|
away_slug, away_inst, away_id, away_name = pack_team(away_team, guess_away_fallback)
|
|
|
|
|
|
|
|
|
|
# Winner/loser
|
|
|
|
|
winner_slug = winner_inst = winner_id = loser_slug = loser_inst = loser_id = ""
|
|
|
|
|
if isinstance(home_runs, int) and isinstance(away_runs, int):
|
|
|
|
|
if home_runs > away_runs:
|
|
|
|
|
@@ -399,12 +391,10 @@ def main(
|
|
|
|
|
winner_slug, winner_inst, winner_id = away_slug, away_inst, away_id
|
|
|
|
|
loser_slug, loser_inst, loser_id = home_slug, home_inst, home_id
|
|
|
|
|
|
|
|
|
|
# Meta from perspectives
|
|
|
|
|
loc = (p_home["location"] if p_home else "") or (p_away["location"] if p_away else "")
|
|
|
|
|
status = (p_home["status"] if p_home else "") or (p_away["status"] if p_away else "")
|
|
|
|
|
source_urls = sorted({x["source_url"] for x in p})
|
|
|
|
|
|
|
|
|
|
# -------- NEW: fetch game start time from game page --------
|
|
|
|
|
time_local = ""
|
|
|
|
|
if fetch_time and game_id:
|
|
|
|
|
if game_id in time_cache:
|
|
|
|
|
|