Skip to main content

Overview

After authenticating with Yahoo, you’ll see a list of all your fantasy basketball leagues. The league selection process filters and displays only head-to-head category leagues, organized by season and team name.

Fetching Your Leagues

The /select route queries Yahoo’s API to retrieve all your leagues:
main.py
@app.route("/select")
def select():
    if "token" not in session:
        return redirect(url_for("index"))
    
    raw = yahoo_api(
        "fantasy/v2/users;use_login=1/games;game_codes=nba/leagues;out=teams"
    )
    # ... parse leagues

API Query Breakdown

  • users;use_login=1: Get data for the currently logged-in user
  • games;game_codes=nba: Filter to NBA (basketball) games only
  • leagues;out=teams: Fetch leagues with team information included
This single API call retrieves all your basketball leagues across all seasons.

Filtering Head-to-Head Leagues

The app only displays head-to-head category leagues (not points-based or rotisserie):
main.py
for lg in _safe_iter(_first(game, "leagues"), "league"):
    if _first(lg, "scoring_type") != "head":
        continue  # Skip non-head-to-head leagues
    
    # ... process this league
If you don’t see a league listed, verify it’s configured as “Head-to-Head Categories” in Yahoo Fantasy Basketball settings.

Finding Your Team

For each league, the app identifies which team belongs to you:
main.py
for team_container in _safe_iter(_first(lg, "teams"), "team"):
    team_data_list = team_container[0] if isinstance(team_container, list) else []
    
    for entry in team_data_list:
        if "managers" in entry and _is_owner(entry["managers"], guid):
            owner_team = entry.get("name", fallback)
            break

Owner Identification

The _is_owner helper checks if you’re the team manager:
main.py
def _is_owner(managers_blob: Any, guid: str) -> bool:
    for m in _safe_iter(managers_blob, "manager"):
        if _first(m, "guid") == guid or str(_first(m, "is_current_login")) == "1":
            return True
    return False
The app matches your team using both your Yahoo GUID and the is_current_login flag for maximum reliability.

League List Display

Leagues are displayed sorted by recency and team name:
main.py
leagues.sort(
    key=lambda x: (
        -int(x["season"]) if x["season"].isdigit() else 0,
        x["team_name"]
    )
)

return render_template("select.html", leagues=leagues)

Display Format

Each league shows:
  • Season: The NBA season year (e.g., “2024”)
  • Team Name: Your team’s name in that league
  • League Key: A unique identifier used for API calls

The Selection Interface

HTML Structure

The selection page presents a dropdown menu:
select.html
<select id="team" name="league_key" class="form-select">
  <option value="" disabled selected>— Select your team —</option>
  {% for l in leagues %}
    <option value="{{ l.league_key }}" data-team="{{ l.team_name }}">
      {{ l.season }} – {{ l.team_name }}
    </option>
  {% endfor %}
</select>

JavaScript Enhancement

When you select a league, JavaScript captures the team name:
select.html
const teamSelector = document.getElementById('team');
const teamField = document.getElementById('teamField');

teamSelector.addEventListener('change', () => {
  const selectedOption = teamSelector.options[teamSelector.selectedIndex];
  teamField.value = selectedOption.dataset.team;
});
  • league_key: Used for all Yahoo API calls (format: nba.l.12345)
  • team_name: Displayed in the dashboard header and used to identify your team in league data
Both values are stored in the session when you submit the form.

Submitting Your Selection

When you click “Continue to Dashboard”, the form posts to /greet:
main.py
@app.route("/greet", methods=["POST"])
def greet():
    session["league_key"] = request.form["league_key"]
    session["team_name"] = request.form["team_name"]
    return redirect(url_for("dashboard"))
These session values persist throughout your session and are used by all dashboard features.

Switching Leagues

To switch to a different league:
  1. Navigate back to the league selection page (via navbar or direct URL)
  2. Select a different league from the dropdown
  3. Your session updates with the new league information
Switching leagues preserves your authentication token but resets all league-specific data like cached statistics.

League Data Structure

Each league object contains:
{
    "season": "2024",
    "league_key": "423.l.12345",
    "team_name": "Thunder Dunkers"
}

Season Format

Seasons are represented as:
  • Single year: “2024” for the 2024-25 NBA season
  • The year represents when the season started

League Key Format

League keys follow Yahoo’s format: {game_id}.l.{league_id} Example: 423.l.12345
  • 423: NBA game ID for the current season
  • l: Denotes a league
  • 12345: Your specific league ID

Troubleshooting

Possible reasons:
  1. Not in any head-to-head category leagues: The app only shows H2H leagues
  2. Authentication expired: Try logging out and back in
  3. No active NBA leagues: Verify you have active Yahoo Fantasy Basketball leagues
Check the server logs for API errors.
If the wrong team appears:
  1. The app uses Yahoo’s is_current_login flag and your GUID
  2. Co-managed teams may show the first manager’s name
  3. Try refreshing the page or re-authenticating
The team name comes directly from Yahoo’s API response.
This is normal behavior:
  • The app shows all your leagues, including past seasons
  • Leagues are sorted with most recent first
  • You can select any season to view historical data
  • Some features may have limited data for past seasons

Session Data

After selection, your session contains:
session = {
    "token": {/* OAuth token data */},
    "league_key": "423.l.12345",
    "team_name": "Thunder Dunkers"
}
This data is used throughout the dashboard to:
  • Make league-specific API calls
  • Display your team name
  • Identify your team in comparisons
  • Filter data to your perspective

Next Steps

Dashboard Navigation

Explore the dashboard interface and tabs

Interpreting Analytics

Learn how to read the analytics and insights

Build docs developers (and LLMs) love