Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .gitignore

This file was deleted.

21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
25 changes: 22 additions & 3 deletions utils/streamlit_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
"""
Expand All @@ -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

Expand Down Expand Up @@ -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():
"""
Expand Down