Skip to content

Repository files navigation

Fantasy Reporter

A Python application that generates weekly PDF reports for your Sleeper fantasy football league. The reports include team standings, matchups, team photos, points, and humorous matchup commentary.

Features

  • League Standings: Complete standings table with team names, win-loss records, total points, and team avatars
  • Weekly Matchups: Detailed matchup breakdowns with team photos and current week points
  • Funny Comments: Automatically generated humorous commentary for each matchup
  • Team Photos: Displays team avatars from Sleeper
  • Automated Scheduling: Ready for cron job setup

Requirements

  • Python 3.7+
  • Internet connection (for API calls and image downloads)

Installation

  1. Navigate to the project directory:
cd fantasy-reporter
  1. Create a virtual environment (recommended):
python3 -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt

Usage

Manual Execution

Run the script directly:

python fantasy_reporter.py

The script will:

  • Automatically determine the current NFL week
  • Fetch league data from the Sleeper API
  • Generate a PDF report in the reports/ directory
  • Name the file with a timestamp (e.g., fantasy_report_20241215_143022.pdf)

Specify a Week

To generate a report for a specific week, modify the main() function in fantasy_reporter.py:

create_pdf_report(output_path, week=5)  # Generate report for week 5

Cron Job Setup

To run the report automatically on a schedule (e.g., every Tuesday morning after games finish):

  1. Open your crontab:
crontab -e
  1. Add a cron job. For example, to run every Tuesday at 9 AM:
0 9 * * 2 cd /path/to/fantasy-reporter && /usr/bin/python3 fantasy_reporter.py >> /path/to/fantasy-reporter/cron.log 2>&1

Or if using a virtual environment:

0 9 * * 2 cd /path/to/fantasy-reporter && /path/to/fantasy-reporter/venv/bin/python fantasy_reporter.py >> /path/to/fantasy-reporter/cron.log 2>&1

Cron Schedule Examples

  • Every Tuesday at 9 AM: 0 9 * * 2
  • Every Monday at 8 AM: 0 8 * * 1
  • Every day at 6 PM: 0 18 * * *
  • Every Sunday at 10 AM: 0 10 * * 0

Cron Schedule Format

* * * * *
│ │ │ │ │
│ │ │ │ └─── Day of week (0-7, Sunday = 0 or 7)
│ │ │ └───── Month (1-12)
│ │ └─────── Day of month (1-31)
│ └───────── Hour (0-23)
└─────────── Minute (0-59)

Configuration

Set your Sleeper league ID by copying .env.example to .env and filling in your league ID:

cp .env.example .env
# Edit .env and set SLEEPER_LEAGUE_ID=your_league_id_here

Your league ID can be found in the URL when viewing your league on sleeper.app.

Output

Reports are saved in the reports/ directory with filenames like:

  • fantasy_report_20241215_143022.pdf

Each report includes:

  1. Cover Page: League name, week number, generation timestamp
  2. Standings Page: Complete league standings with rankings
  3. Matchups Page: All weekly matchups with team photos, points, and commentary

API Rate Limits

The Sleeper API has a rate limit of approximately 1000 requests per minute. This script makes:

  • 1 request for league info
  • 1 request for rosters
  • 1 request for users
  • 1 request for matchups
  • 1 request for NFL state
  • Multiple requests for avatar images (one per team/user)

Total: ~10-20 requests per report generation, well within limits.

Troubleshooting

Image Download Errors

If team avatars fail to download, the script will continue without them. Check your internet connection and Sleeper CDN availability.

API Errors

If you receive API errors:

  • Verify the league ID is correct
  • Check that the league is active
  • Ensure you have internet connectivity
  • Wait a few minutes and try again (rate limiting)

PDF Generation Errors

Ensure you have write permissions in the reports/ directory. The script will create this directory if it doesn't exist.

License

This project is for personal use. Sleeper API is provided by Sleeper (https://sleeper.app).

About

Generate weekly recaps for your Fantasy Football league!

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages