oyshan / fplstats

Fantasy Premier League Mini League Statistics
1 stars 1 forks source link

FPL Mini League Statistics

Get fun and mind-blowing statistics about your FPL mini league season.

Shout out to https://github.com/amosbastian/fpl for making my life easier.

Setup / installation

Create virtual env

virtualenv env

Activate virtual env

source env/bin/activate

Install requirements

pip install -r requirements.txt

Fetch league data

Before analyzing, you need to fetch data. To fetch data for the current season up to the latest gameweek for your league, run:

python fpl-stats/scripts/fetch_league.py \
    --league=<fpl_league_id> \
    --email=<fpl_username> \
    --cookie=<fpl_cookie> \
    [--password=<fpl_password>] \
    [--force-fetch-all] \
    [--fetch-live] \
    [> <output_file>]

The cookie should be extracted from the browser after logging in to the FPL website (copy/paste the document.cookie value from the dev tool console after logging in) which should increase the success chance of authenticating.

The password could either be provided as an argument, or it will be prompted.
If you want to fetch everything regardless of what data you already have, add the --force-fetch-all argument flag.
If you want to fetch "live" data for an ongoing/current, gameweek, add the --fetch-live argument flag.

This will fetch data from fantasy.premierleague.com and output the following files:

Analyze league data

After fecthing data you can analyze your mini league season data by running:

python fpl-stats/scripts/analyze_league.py \
    --season=<startyear_endyear> \
    --league=<fpl_league_id> \
    [--live] \
    [--disable-prompt] \
    [> <output_file>]

This will output all statistics for your league.
If you want to analyze the current/ongoing gameweek "live", add the --live argument flag.
If you don't want to press Enter to continue between each statistic, add the --disable-prompt argument.
You could also output the results to file by adding > output.txt if you want to store the results.

You could also start your own python shell and get the statistics you are interested in, e.g.

python
>>> from fplstats.analyzers import LeagueAnalyzer
>>> # Init
>>> league_analyzer = LeagueAnalyzer(<season_id>, <league_id>)
>>> # Get the statistics you want, e.g.
>>> league_analyzer.get_captain_hindsight()
TEAM          CAPTAIN POINTS
Soccer MC's   1413
CHANGE NAME   1337
>>> # Etc.