diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 935c012..0000000 --- a/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -__pycache__ -.venv -test.py -data.json -.streamlit/secrets.toml \ No newline at end of file diff --git a/README.md b/README.md index 63d791e..3bd023e 100644 --- a/README.md +++ b/README.md @@ -94,10 +94,27 @@ GitHub Contribution Tracker is a **Streamlit** web application that visualizes G ## Usage -1. Enter your **GitHub Username**. -2. Provide a **GitHub Personal Access Token** (with `read:user` and `repo` scopes for GraphQL API access). +1. Enter your credentials into `.stremlit/secrets.toml`. +2. Provide a **GitHub Personal Access Token** (with `read:user` and `repo` scopes for GraphQL API access), your **GitHub username**, and set **autoload** to `true` or `false` _(`true` recommended)_. + + `secrets.toml` example: + ``` + token = "github_pat_..." + username = "my-github-username" + autoload = true + ``` + 3. View detailed stats, visualizations, and achievements based on your contribution data. +### Control browser auto-open via server config + +If you don't want your browser to automatically open the dashboard everytime you run `streamlit run app.py`, just add the following two lines to your `config.toml` in `.streamlit` folder: + +``` +[server] +headless = true +``` + ### How to Generate a GitHub Personal Access Token 1. Go to [GitHub Developer Settings](https://github.com/settings/tokens). diff --git a/utils/streamlit_ui.py b/utils/streamlit_ui.py index 129611f..e4df691 100644 --- a/utils/streamlit_ui.py +++ b/utils/streamlit_ui.py @@ -2,7 +2,11 @@ from streamlit import session_state as sst from utils.fetch_github_data import fetch_star_count -TOKEN = st.secrets["token"] +# Read secrets with fallback for local/dev usage. +# Keep `token` required in deployed environments. +TOKEN = st.secrets.get("token", "") if hasattr(st, "secrets") else "" +DEFAULT_USERNAME = st.secrets.get("username", "") if hasattr(st, "secrets") else "" +AUTOLOAD = st.secrets.get("autoload", False) if hasattr(st, "secrets") else False def base_ui(): """ @@ -24,9 +28,12 @@ def base_ui(): # Title and input title_bar() - with st.sidebar: + with st.sidebar.expander("Controls", expanded=not AUTOLOAD): form() # Streamlit Form + if AUTOLOAD and sst.username and sst.token: + sst.button_pressed = True + if sst.username and sst.token and sst.button_pressed: nav_ui() # Sidebar navigation menu @@ -75,13 +82,25 @@ def initialize_sst(): # Initializing session state if 'username' not in sst: - sst.username = '' + sst.username = DEFAULT_USERNAME if 'user_token' not in sst: sst.user_token = '' if 'token_present' not in sst: sst.token_present = False if 'button_pressed' not in sst: sst.button_pressed = False + if 'token' not in sst: + sst.token = TOKEN + + # If we have a username in secrets, prefill the input and mark the button state + if DEFAULT_USERNAME and not sst.username: + sst.username = DEFAULT_USERNAME + # If a token is present in secrets and user has not manually provided one, use it + if TOKEN and not sst.user_token: + sst.user_token = TOKEN + sst.token = TOKEN + sst.token_present = False + def title_bar(): """