Spaces:
Running
Running
Jon Solow
commited on
Commit
•
78f5251
1
Parent(s):
6e1d434
Make league selector function
Browse files
src/pages/51_League_Results_Summary.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
from config import DEFAULT_ICON, SEASON
|
4 |
+
from login_component import is_token_in_session
|
5 |
+
from shared_page import common_page_config
|
6 |
+
|
7 |
+
|
8 |
+
@st.cache_resource(ttl=60 * 60 * 24)
|
9 |
+
def get_all_league_settings_with_cache(season: int):
|
10 |
+
return st.session_state.yahoo_client.get_all_logged_in_user_league_settings(season=season)
|
11 |
+
|
12 |
+
|
13 |
+
def get_page():
|
14 |
+
page_title = "Yahoo League Scoring Summary"
|
15 |
+
st.set_page_config(page_title=page_title, page_icon=DEFAULT_ICON, layout="wide")
|
16 |
+
common_page_config()
|
17 |
+
st.title(page_title)
|
18 |
+
|
19 |
+
if not is_token_in_session():
|
20 |
+
st.write(
|
21 |
+
"You must authorize the application to access your account in order to use this feature."
|
22 |
+
" Please click Login button above."
|
23 |
+
)
|
24 |
+
|
25 |
+
else:
|
26 |
+
selected_season = st.selectbox("Select Season", list(range(SEASON, 2012, -1)))
|
27 |
+
user_leagues = get_all_league_settings_with_cache(season=selected_season)
|
28 |
+
selected_league = st.selectbox("Select league", user_leagues, format_func=lambda x: x.name)
|
29 |
+
st.header(f"{selected_league.name} - {selected_league.season}")
|
30 |
+
|
31 |
+
|
32 |
+
if __name__ == "__main__":
|
33 |
+
get_page()
|
src/yahoo_client.py
CHANGED
@@ -152,6 +152,10 @@ class YahooFantasyClient:
|
|
152 |
df = pd.DataFrame(self.parse_weeks_matchups(week=all_weeks, league_key=league_key))
|
153 |
return df
|
154 |
|
|
|
|
|
|
|
|
|
155 |
|
156 |
class MatchupTeam(BaseModel):
|
157 |
team_id: str
|
|
|
152 |
df = pd.DataFrame(self.parse_weeks_matchups(week=all_weeks, league_key=league_key))
|
153 |
return df
|
154 |
|
155 |
+
def get_all_logged_in_user_league_settings(self, season: str) -> list[LeagueSettings]:
|
156 |
+
all_league_keys = self.find_all_leagues_for_logged_in_user(season)
|
157 |
+
return [self.parse_league_settings(lk) for lk in all_league_keys]
|
158 |
+
|
159 |
|
160 |
class MatchupTeam(BaseModel):
|
161 |
team_id: str
|