GithubHelp home page GithubHelp logo

spinach / fantasypremierleague.py Goto Github PK

View Code? Open in Web Editor NEW
130.0 26.0 38.0 163 KB

⚽ Statistics for your mini leagues.

Python 100.00%
premierleague league player gameweek python-script mini-league statistics fantasypremierleague-api api fantasy-premier-league

fantasypremierleague.py's Introduction

⚽ FantasyPremierLeague-Api-Python

FantasyPremierLeague-Api-Python helps you access the data of the Fantasy PremierLeague game. It is intended for use by people who want to get statistical data around the game for fun. For now, there is a cool example where you can get interesting statistics about your mini league.

For now, you can get 2 main things out of the python script:

  • Distribution of players that are being picked in a specific League and GameWeek
  • Distribution of players being captained in a specific League and GameWeek

Getting Started

These instructions will get you a copy of the project up and running on your local machine.

Prerequisities

After cloning the project, you need to have Python 2.7 installed on your machine. Go to Download Python 2.7.12

If you want to use Python 3, check branch python3.

You also need to have the requests, tqdm and unicodecsv library on your machine. Run the following on your terminal:

pip install -r requirements.txt

Or you can install individually by

pip3 install requests tqdm unicodecsv

Usage

For now, you can get 2 main things out of the python script:

  • Distribution of players that are being picked in a specific League and GameWeek
  • Distribution of players being captained in a specific League and GameWeek

Follow these easy steps to get these results for your league:

  1. Go to https://fantasy.premierleague.com/ and login.
  2. Go to leagues, and then click on the league you want to analyse
  3. Check out the URL. It will be something like https://fantasy.premierleague.com/a/leagues/standings/336217/classic. Save the 336217 number, which is your league entry id.
  4. Decide what GameWeek you want to analyse, let's say it's 2, and then check what type of league it is (whether h2h or classic)
  5. Run the following command at the root of your project by inserting your specific league entry Id and GameWeek Number: python playersPickedInLeague.py --league 336217 --gameweek 2 --type classic or python playersPickedInLeague.py -l 336217 -g 2 -t classic. For h2h leagues, replace classic with h2h.

Warning: If you get an SSLError issue, then try using the python3 branch. More details about the issue can be found in #2.

Voila, you should be able to see 2 csv files created at the output folder of your project

Also if you want to run in debug mode now add argument -d True or --debug True in above command line

How to Contribute

This is just an example of what you can do with the fpl apis. I'm sure there are lots of cool ideas, so feel free to suggest by submitting an issue, or even write it yourself and send me a PR :)

DONE

TODO

  • Idea: Output file with every player selected per manager in league

fantasypremierleague.py's People

Contributors

spinach avatar yathomasi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fantasypremierleague.py's Issues

KeyError: 'elements'

Hey there,

I've tried with both Python 2 & Python 3 and when I run the command as indicated in the Readme file I receive the following error:

Traceback (most recent call last):
  File "playersPickedInLeague.py", line 87, in <module>
    for element in allPlayers["elements"]:
KeyError: 'elements'

Appreciate your help and many thanks for developing it!

Authorization error

Sometimes following error occurs

classic league mode
Errors occurred in getting entries/managers in the league.
'standings'
Traceback (most recent call last):
  File "playersPickedInLeague.py", line 112, in <module>
    entries = getUserEntryIds(leagueIdSelected, pageCount, leagueStandingUrl)
  File "playersPickedInLeague.py", line 35, in getUserEntryIds
    managers = jsonResponse["standings"]["results"]
KeyError: 'standings'

Its because of authorization error in new django api
i tried this link:https://medium.com/@bram.vanherle1/fantasy-premier-league-api-authentication-guide-2f7aeb2382e4
but it didn't worked for me
For now you need open those link from your browser including the next page thats empty

Idea: Output file with every player selected per manager in league

Thank you for a great project for us FPL geeks!
I have an idea for further development, but my skills are lacking.

Would it be possible to tweak the script to output a file containing what players each manager selected, if the player was on the field/benched, and who was captained/VC?

SSL error?

Got SSL Error while running the script fom MAC; Any idea:

Traceback (most recent call last):
  File "playersPickedInLeague.py", line 82, in <module>
    getPlayersInfo()
  File "playersPickedInLeague.py", line 20, in getPlayersInfo
    r = requests.get(PLAYERS_INFO_URL, verify=False)
  File "/Library/Python/2.7/site-packages/requests/api.py", line 72, in get
    return request('get', url, params=params, **kwargs)
  File "/Library/Python/2.7/site-packages/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/Library/Python/2.7/site-packages/requests/sessions.py", line 508, in request
    resp = self.send(prep, **send_kwargs)
  File "/Library/Python/2.7/site-packages/requests/sessions.py", line 618, in send
    r = adapter.send(request, **kwargs)
  File "/Library/Python/2.7/site-packages/requests/adapters.py", line 506, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='fantasy.premierleague.com', port=443): Max retries exceeded with url: /drf/bootstrap-static (Caused by SSLError(SSLError(1, u'[SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590)'),))
~ 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.