Repository
https://github.com/amosbastian/fpl
Pull request
https://github.com/amosbastian/fpl/pull/9
As mentioned in my task request I have been getting a lot of emails about fpl from users and developers, so I have started working on it again. The Premier League season has also started again, so some of my gained motivation stems from that as well. Since it has been a while since I last worked on this package I have updated and refactored quite a lot, as I like to think that I have improved my programming during that time. I have also added some new functions, classes and more!
What is fpl?
It's a Python wrapper for the Fantasy Premier League API. For those who don't know what the Fantasy Premier League is, it's basically a game where you score points depending on the performance of your players in real life in the Premier League. It's quite popular on here and overall there are about 5 million players worldwide and I personally love it!
The big refactor
I think fpl was the first Python package I had ever uploaded to PyPi, so its structure wasn't very optimal. It actually did contain unit tests, but only for the FPL class and they weren't up to date, which is far from ideal. Furthermore some properties were missing from classes, there wasn't a way to retrieve your current team, you couldn't retrieve a singular player, but needed to retrieve all of them (takes a long time) and more... so this needed to be fixed!
Properties and structure
The first thing I did was change the folder structure and add a file where I could save all the URLs (constants.py) instead of declaring them in each class separately. Going through the Fantasy Premier League website with Chrome's network console open I found some additional endpoints so they were added as well. I also realised some classes were missing properties for some reason, so these were included too.
Adding the login function
The login function actually already existed in the H2HLeague class, but only for retrieving a league's fixtures. I've now moved it to the FPL class, so users can either log in with their email and password, or set environment variables and log in automatically. This is important because you need to be logged in to retrieve your current team (otherwise others can simply copy your team). Now this can be done using the my_team() function in the User class after logging in!
It returns what?!
As I was checking the unit tests I had written months ago I realised that in some places where you were for example expecting a Player object to be returned, it was returning a dictionary instead. I made sure this time that where you expect an object to be returned, it actually is the case.
Updating all the classes and unit testing
Not only were some properties missing from the classes, but also some functions that make them easier to use. I went through each and every class, added functions that I thought would be useful (if applicable) and then also added unit tests. This took quite a while, but it's definitely nice knowing that changing something doesn't completely break the code.
The User class now contains the my_team() function as I already touched on earlier. It also includes new properties, one of which is the user's watchlist, which is very useful.
A Player object can also now be made by simply passing the player's ID instead of having to retrieve ALL players and then iterating over them to find the one you want. This saves a lot of time, as there are loads of requests that need to be made to retrieve all this information.
The Team class now has a function to retrieve a list of all players (objects) that are playing for the team as well. This is one of those functions that I think should've been there from the start, but at least it's there now!
Both the ClassicLeague and H2HLeague were both missing properties as well, so those were added as well, but other than that, not much changed.
Travis CI
I've set up Travis CI as well, because in the future I really want to look for other contributors and so this was a small, but important addition. Since I had never used it in one of my own projects before, I was actually surprised how easy and quick it was to set up.
This also means I was able to check if everything is compatible with different versions of Python. So I checked for 2.7 and 3.3+, and it seems everything should work fine on those versions.
The Fixture class
In this update I've added the Fixture class, alongside functions in the FPL class to retrieve all fixtures (of a specific gameweek) and a specific fixture. It includes functions to retrieve who scored, assisted etc. during the fixture and all the additional properties that you would expect to see in a fixture. Of course I also wrote some unit tests for this class.
Roadmap
I have quite a few ideas that I want to work on, and so I'll list a couple of them below:
- Currently it's very slow having to retrieve all players, since it requires quite a lot of requests to get all the required information. Locally I have set up a database that syncs itself once a day, and I am doing some research if I could somehow implement this in the package itself. If you have any idea how I could do this, please let me know!
- Add a CLI - I think it would be really cool to see your team with your player's points live in your terminal for example!
- Create a function that linearly optimises a team based on a budget and a given metric - I've done something similar before and I think it would be an amazing feature to add.
- Update its documentation as it is pretty out of date at the moment.
- Read Fluent Python and use that to improve EVERYTHING (it finally arrived)!
I would call it a great progress. :)
travis-ci is a great touch, I would also add 3.6-dev, 3.7-dev versions of Python, so you can see if anything is broken in the upcoming python versions.
I think, that should be another package's responsibility. It may use fpl to sync, and stores the data the database.
Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.
To view those questions and the relevant answers related to your post, click here.
Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]
Thanks a lot Emre! That's a great idea about adding 3.6-dev and 3.7-dev, I'll definitely do that.
I guess I could create another package for it, but I'll probably do this once fpl has all the features I want it to contain.
Thank you for your review, @emrebeyler!
So far this week you've reviewed 7 contributions. Keep up the good work!
Haha this is an interesting looking tool :) Not a big sportsfan myself, but I can see the genius behind this :P Plus there is not too many people making tools like this so even better :)
I like the terminal features you've included as well, I have always hoped it would again become popular to play terminal games.
I didn't include the CLI yet, that's still in the planning phase, haha. And you should definitely get into football, it's great!
Oh I see, that's listed in your roadmap! Well that's just excellent planning and development. I used to play back in highschool, but I switched schools n lost the team :( Just not big into watching sports, though get a couple whiskeys in me and that can change quite a bit :P
hehe I just found this data set http://openfootball.github.io/
Congratulations! Your post has been selected as a daily Steemit truffle! It is listed on rank 19 of all contributions awarded today. You can find the TOP DAILY TRUFFLE PICKS HERE.
I upvoted your contribution because to my mind your post is at least 4 SBD worth and should receive 135 votes. It's now up to the lovely Steemit community to make this come true.
I am
TrufflePig
, an Artificial Intelligence Bot that helps minnows and content curators using Machine Learning. If you are curious how I select content, you can find an explanation here!Have a nice day and sincerely yours,
TrufflePig
Hey, @amosbastian!
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!
Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).
Want to chat? Join us on Discord https://discord.gg/h52nFrV.
Vote for Utopian Witness!
Interesting stuff. Hope it works out.
If you are looking for a cryptocurrency based FPL, you should check out www.FootballCOin.io
Well done.are you a designer??
Not at all!
Congratulations @amosbastian! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :
Award for the total payout received
Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word
STOP
Do not miss the last post from @steemitboard: