acetwo3ee commited on
Commit
0977720
·
verified ·
1 Parent(s): ce12f70

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +6 -3
src/streamlit_app.py CHANGED
@@ -6,7 +6,7 @@ import requests
6
  st.title("WNBA Player Game Logs (2025 Season)")
7
 
8
  # API URL and headers
9
- url = "https://stats.wnba.com/stats/playergamelogs?DateFrom=&DateTo=&GameSegment=&LastNGames=0&LeagueID=10&Location=&MeasureType=Base&Month=0&OpponentTeamID=0&Outcome=&PORound=0&PaceAdjust=N&PerMode=Totals&Period=0&PlusMinus=N&Rank=N&Season=2025&SeasonSegment=&SeasonType=Regular+Season&ShotClockRange=&VsConference=&VsDivision="
10
  headers = {
11
  "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
12
  "Accept": "application/json",
@@ -18,12 +18,12 @@ headers = {
18
  @st.cache_data
19
  def fetch_wnba_data():
20
  try:
21
- response = requests.get(url, headers=headers)
22
  response.raise_for_status() # Check for request errors
23
  data = response.json()
24
  # Extract headers and rows from the first resultSet
25
  result_set = data['resultSets'][0]
26
- api_headers = result_set['headers'] # Use a different name to avoid conflict with global 'headers'
27
  rows = result_set['rowSet']
28
  # Create DataFrame
29
  df = pd.DataFrame(rows, columns=api_headers)
@@ -34,6 +34,9 @@ def fetch_wnba_data():
34
  except KeyError as e:
35
  st.error(f"Error parsing JSON: {e}")
36
  return None
 
 
 
37
 
38
  # Fetch and display data
39
  df = fetch_wnba_data()
 
6
  st.title("WNBA Player Game Logs (2025 Season)")
7
 
8
  # API URL and headers
9
+ url = "https://stats.wnba.com/stats/playergamelogs?LastNGames=10&LeagueID=10&MeasureType=Base&PerMode=Totals&Season=2025&SeasonType=Regular+Season"
10
  headers = {
11
  "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
12
  "Accept": "application/json",
 
18
  @st.cache_data
19
  def fetch_wnba_data():
20
  try:
21
+ response = requests.get(url, headers=headers, timeout=10) # Add timeout of 10 seconds
22
  response.raise_for_status() # Check for request errors
23
  data = response.json()
24
  # Extract headers and rows from the first resultSet
25
  result_set = data['resultSets'][0]
26
+ api_headers = result_set['headers'] # Use a different name to avoid conflict
27
  rows = result_set['rowSet']
28
  # Create DataFrame
29
  df = pd.DataFrame(rows, columns=api_headers)
 
34
  except KeyError as e:
35
  st.error(f"Error parsing JSON: {e}")
36
  return None
37
+ except Exception as e:
38
+ st.error(f"Unexpected error: {e}")
39
+ return None
40
 
41
  # Fetch and display data
42
  df = fetch_wnba_data()