File size: 1,385 Bytes
52e3bda
 
af23901
 
991e6b5
52e3bda
 
 
 
 
991e6b5
 
 
 
 
52e3bda
 
 
 
 
 
 
 
991e6b5
52e3bda
 
991e6b5
 
 
 
 
af23901
 
52e3bda
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import streamlit as st


from analyze_yahoo import analyze_league
from config import DEFAULT_ICON, SEASON
from shared_page import common_page_config

from login_component import is_token_in_session


@st.cache_resource(ttl=60 * 60 * 24)
def get_all_league_settings_with_cache(season: int):
    return st.session_state.yahoo_client.get_all_logged_in_user_league_settings(season=season)


def get_page():
    page_title = "Yahoo FF League Simulation - ADMIN"
    st.set_page_config(page_title=page_title, page_icon=DEFAULT_ICON, layout="wide")
    common_page_config()
    st.title(page_title)

    if not is_token_in_session():
        st.write("You must be a site admin in order to use this feature." " Please click Login button above.")
    elif st.session_state.user_admin is not True:
        st.write("You must be a site admin in order to use this feature.")
    else:

        selected_season = st.selectbox("Select Season", list(range(SEASON, 2012, -1)))
        user_leagues = get_all_league_settings_with_cache(season=selected_season)
        selected_league = st.selectbox("Select league", user_leagues, format_func=lambda x: x.name)
        st.header(f"{selected_league.name} - {selected_league.season}")
        if st.button("Analyze League"):
            analyze_league(selected_league.league_key, st.session_state.yahoo_client)


if __name__ == "__main__":
    get_page()