fix(data): add timezone handling for Sports-Reference scrapers and new stadiums
- Add ET timezone (America/New_York) to all Sports-Reference scrapers:
- NBA: Basketball-Reference times parsed as ET
- NFL: Pro-Football-Reference times parsed as ET
- NHL: Hockey-Reference times parsed as ET
- MLB: Baseball-Reference times parsed as ET
- Document source timezones in scraper docstrings
- Add 11 new stadiums to STADIUM_MAPPINGS:
- NFL: 5 international venues (Corinthians Arena, Croke Park,
Olympic Stadium Berlin, Santiago Bernabéu, Tom Benson Hall of Fame)
- MLS: 4 alternate venues (Miami Freedom Park, Citi Field,
LA Memorial Coliseum, M&T Bank Stadium)
- NWSL: 2 alternate venues (Northwestern Medicine Field, ONE Spokane)
- Add 15 stadium aliases for MLS/NWSL team-based lookups
- Fix CanonicalSyncService to sync timezone identifier to SwiftData
- Update debug logging to use stadium timezone for display
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
from datetime import datetime, date
|
||||
from typing import Optional
|
||||
from zoneinfo import ZoneInfo
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
from .base import BaseScraper, RawGameData, ScrapeResult
|
||||
@@ -40,6 +41,11 @@ class NHLScraper(BaseScraper):
|
||||
1. Hockey-Reference - Most reliable for NHL
|
||||
2. NHL API - Official NHL data
|
||||
3. ESPN API - Backup option
|
||||
|
||||
Source Timezones:
|
||||
- hockey_reference: Eastern Time (ET) - times displayed as "7:00p"
|
||||
- nhl_api: UTC - ISO 8601 format with "Z" suffix (startTimeUTC field)
|
||||
- espn: UTC - ISO 8601 format with "Z" suffix
|
||||
"""
|
||||
|
||||
def __init__(self, season: int, **kwargs):
|
||||
@@ -158,6 +164,25 @@ class NHLScraper(BaseScraper):
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
# Get game start time (format: "7:00p" or "10:30p") - times are in ET
|
||||
time_cell = row.find("td", {"data-stat": "time_game"})
|
||||
if time_cell:
|
||||
time_text = time_cell.get_text(strip=True)
|
||||
if time_text:
|
||||
try:
|
||||
# Parse time like "7:00p" or "10:30p"
|
||||
# Normalize: "7:00p" -> "7:00 PM", "10:30p" -> "10:30 PM"
|
||||
time_normalized = time_text.replace("p", " PM").replace("a", " AM")
|
||||
game_time = datetime.strptime(time_normalized, "%I:%M %p")
|
||||
# Combine date and time with ET timezone (Hockey-Reference uses ET)
|
||||
game_date = game_date.replace(
|
||||
hour=game_time.hour,
|
||||
minute=game_time.minute,
|
||||
tzinfo=ZoneInfo("America/New_York"),
|
||||
)
|
||||
except ValueError:
|
||||
self._logger.debug(f"Could not parse time: {time_text}, using midnight")
|
||||
|
||||
# Get teams
|
||||
visitor_cell = row.find("td", {"data-stat": "visitor_team_name"})
|
||||
home_cell = row.find("td", {"data-stat": "home_team_name"})
|
||||
|
||||
Reference in New Issue
Block a user