Skip to content

A simple script designed for Sleeper fantasy football league commissioners that pulls data from the Sleeper API and puts it into a Google Sheet.

Notifications You must be signed in to change notification settings

oldman-gg/Sleeper-Sheets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Sleeper-Sheets

GitHub last commit

Sleeper-Sheets is a Python project that interacts with the Sleeper fantasy football API to fetch league data and update Google Sheets with weekly performance metrics intended to make life a bit easier for Sleeper commissioners. The project includes retrieval of weekly scoring across multiple league years, tracking weekly wins and league incentives, and tracking all-time league records.

Features

  • Fetches user, roster, and matchup data from the Sleeper API
  • Processes weekly league fantasy football data
  • Uploads processed data to Google Sheets

Installation

Clone the Repository

Install Dependencies

  • pip install -r requirements.txt

Setup Configuration

  • Copy the config-example.json and rename it to config.json and fill in your configuration details:
{
    "spreadsheet_id": "your_google_sheet_id",
    "service_account_file": "path_to_your_service_account_file.json",
    "players_file": "path_to_players_data.json",
    "league_ids": {
        "2021": "your_league_id_2021",
        "2022": "your_league_id_2022",
        "2023": "your_league_id_2023",
        "2024": "your_league_id_2024"
    }
}

Note: it is not required to enter a league ID for each season.

Usage

Set Up Google Sheets API

  • Ensure you have a Google service account and have shared your Google Sheets with the service account email address.

Run the Script

  • python main.py
  • This will initialize the script, process the season data for each league, and upload the results to Google Sheets.

Script Overview

SleeperSheets Class

The SleeperSheets class handles the following operations:

  • Initialization (init): Loads configuration settings from config.json.
  • Load Player Data (load_player_data): Loads player data from a JSON file.
  • Fetch Users (fetch_users): Retrieves user data for a given league.
  • Fetch Matchups (fetch_matchups): Retrieves matchup data for a specific week.
  • Fetch Rosters (fetch_rosters): Retrieves roster data for a league.
  • Filter Rows (filter_rows): Filters out users with more than 5 weeks of zero points.
  • Process Season (process_season): Processes the season data and returns a DataFrame.
  • Upload to Google Sheets (upload_to_google_sheets): Uploads a DataFrame to a specified Google Sheets sheet.
  • Create Summary Sheet (create_summary_sheet): Creates or updates the "League Records" sheet with the highest-scoring user details.
  • Run (run): Main method to execute data processing and uploading tasks.

Configuration File

The configuration file config.json includes:

  • spreadsheet_id: Google Sheets ID where data will be uploaded.
  • service_account_file: Path to the Google service account credentials JSON file.
  • players_file: Path to the JSON file containing player data.
  • league_ids: Dictionary mapping years to Sleeper league IDs.

Google Sheets Setup

Ensure that:

  • You have a valid Google Sheets ID.
  • Your service account has access to the Google Sheet

Contributing

Feel free to submit issues or pull requests if you have improvements, bug fixes, or want to tackle any of the to dos below.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Replace placeholders like yourusername, your_google_sheet_id, and path_to_your_service_account_file.json with your actual details.

To Dos

  • Introduce logic of current NFL week + year so that incomplete NFL weeks are not counted in sheets
  • Introduce AI to provide a summary of the the week and an overview of the current season's incentives