Jon Solow
Fix typehint
c762be5
raw
history blame
1 kB
import pandas as pd
def get_full_schedule(season_int: str | int) -> pd.DataFrame:
url = f"https://www.pro-football-reference.com/years/{season_int}/games.htm#games"
df = pd.read_html(url)[0]
# remove extra header rows in table
df = df[df.Week != "Week"]
return df
def get_week_team_time_map(df_schedule: pd.DataFrame) -> dict[int, dict[str, pd.Timestamp]]:
min_week = 1
max_week = 23
week_team_time_map: dict[int, dict[str, pd.Timestamp]] = {k: {} for k in range(min_week, max_week + 1)}
for _, row in df_schedule.iterrows():
game_time = pd.to_datetime(row.Date + " " + row.Time, yearfirst=True)
week_team_time_map[int(row.Week)][row["Winner/tie"]] = game_time
week_team_time_map[int(row.Week)][row["Loser/tie"]] = game_time
return week_team_time_map
def get_season_time_map(season_int: str | int) -> dict[int, dict[str, pd.Timestamp]]:
df_schedule = get_full_schedule(season_int)
return get_week_team_time_map(df_schedule)