acetwo3ee commited on
Commit
e80e40d
·
verified ·
1 Parent(s): 6e96e9d

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +9 -8
src/streamlit_app.py CHANGED
@@ -1,16 +1,15 @@
1
  import streamlit as st
2
  import requests
3
  import pandas as pd
4
- import json
5
 
6
- st.title("WNBA Player Game Log - RapidAPI")
7
 
8
  player_id = st.text_input("Enter Player ID", "4433403")
9
 
10
- if st.button("Fetch Player Game Log"):
11
  st.info("Fetching data, please wait...")
12
 
13
- url = f"https://wnba-api.p.rapidapi.com/player-gamelog?playerId={player_id}"
14
 
15
  headers = {
16
  "x-rapidapi-key": "1ac1586d40msh8f06d59fafd1b99p180008jsn0ed93153e2d7",
@@ -24,14 +23,16 @@ if st.button("Fetch Player Game Log"):
24
  data = response.json()
25
  st.success("Data fetched successfully!")
26
 
27
- if isinstance(data, dict) and "data" in data:
28
- df = pd.DataFrame(data["data"])
 
 
29
  st.dataframe(df)
30
 
31
  csv = df.to_csv(index=False).encode("utf-8")
32
- st.download_button("Download CSV", csv, "player_gamelog.csv", "text/csv")
33
  else:
34
- st.warning("No valid 'data' field found in response.")
35
  else:
36
  st.error(f"Request failed with status code: {response.status_code}")
37
 
 
1
  import streamlit as st
2
  import requests
3
  import pandas as pd
 
4
 
5
+ st.title("WNBA Player Overview - RapidAPI")
6
 
7
  player_id = st.text_input("Enter Player ID", "4433403")
8
 
9
+ if st.button("Fetch Player Overview"):
10
  st.info("Fetching data, please wait...")
11
 
12
+ url = f"https://wnba-api.p.rapidapi.com/player-overview?playerId={player_id}"
13
 
14
  headers = {
15
  "x-rapidapi-key": "1ac1586d40msh8f06d59fafd1b99p180008jsn0ed93153e2d7",
 
23
  data = response.json()
24
  st.success("Data fetched successfully!")
25
 
26
+ st.json(data) # Show raw JSON
27
+
28
+ if isinstance(data, dict):
29
+ df = pd.json_normalize(data)
30
  st.dataframe(df)
31
 
32
  csv = df.to_csv(index=False).encode("utf-8")
33
+ st.download_button("Download CSV", csv, "player_overview.csv", "text/csv")
34
  else:
35
+ st.warning("Unexpected response structure.")
36
  else:
37
  st.error(f"Request failed with status code: {response.status_code}")
38