Improving my FPL bot for Reddit!

in fpl •  11 days ago






https://github.com/amosbastian/FPLbot

After adding a player vs. player comparison, I finally set up the bot on a droplet last week. I posted about it on Reddit and as you can see it was very well received! It is being used a lot (nearly 100 comments a day), which is great to see. It also means I've received some feedback, and so I decided to quickly implement some of the suggestions I received!

https://github.com/amosbastian/FPLbot/pull/6
https://github.com/amosbastian/FPLbot/pull/7
https://github.com/amosbastian/FPLbot/pull/9

https://www.reddit.com/user/FantasyPL_bot

Changing the player vs. player table

The player vs. player table wasn't very mobile friendly before, which someone pointed out immediately. They suggested to create a separate table for each player, and to simply stack them on top of each other, and so that's what I did. This will also allow for a comparison of more than 2 players in the future, which I might implement as well.

Improving the tables!



Improved tables for goalkeepers

I also made some other improvements to the tables in general. One problem was that comparing goalkeepers was pointless, because the tables only included stuff like expected goals and assists, which obviously isn't relevant to them. To solve this I decided to create a table that included their expected goals against, their saves and more.



Saving the results

Since a player's expected goals against isn't included in a player's information on Understat, I had to get this from their team itself. To do this, I created another function that saves all the team's results in the database, and then use that to get the data. Luckily this was pretty easy to do using my own Understat package!



Creating the goalkeeper table

Another thing I did was add the expected goals against to a defender's table, and also the points the player actually scored during the games (including bonus points). To accomplish this, the first thing I had to do was make sure the matches used when comparing players are only those played in the Premier League (since that's what FPL is about). Finally I needed to somehow get the points and then match this to the respective data from Understat. Luckily I could just use a player's history included in the FPL API to get the points, and all the fixtures on Understat have their own ID, so I could simply compare a player's fixtures with the Premier League fixtures.

You may have noticed that I also switched to use tabulate, which is a Python package for creating tables that I found. It works pretty well for my use case, and also cleaned up the code slightly.

I also made some other QoL changes to the bot, but this post is already getting pretty long. If you want to read more about it, you can check out the Reddit thread I created.

Roadmap

I might add the ability to compare more than 2 players to each other, but will have to see. Will hopefully receive some more suggestions as well!

Usage & installation

FPLbot uses MongoDB to store players in a database, and so it is required to have MongoDB installed. Other than that, it uses fpl to retrieve information from Fantasy Premier League's API, and thus requires Python 3.6+.

git clone git@github.com:amosbastian/FPLbot.git
cd FPLbot
pip install -r requirements.txt



Once installed you should create a config.json file like the above example, but with the correct values. Once you have done this, then you can schedule a cron job to run the bot whenever you want!

Contributing



I've created a Discord server for people interested in programming FPL related things, so if you are interested in helping out, or simply want to know more, then don't hesitate to join! Otherwise you can simply create an issue on GitHub.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

One problem was that comparing goalkeepers was pointless, because the tables only included stuff like expected goals and assists, which obviously isn't relevant to them.

Fun fact; on one of our championship (Galatasaray) our GK scored a penalty for fun. (https://www.transfermarkt.com/fernando-muslera/alletore/spieler/58088) :)

The post is detailed and the code follows best practices. It's also good to see bot have a good use in the reddit community.


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? Chat with us on Discord.

[utopian-moderator]

·

Thank you for your review, @emrebeyler! Keep up the good work!

Hi @amosbastian!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

Hi, @amosbastian!

You just got a 0.05% upvote from SteemPlus!
To get higher upvotes, earn more SteemPlus Points (SPP). On your Steemit wallet, check your SPP balance and click on "How to earn SPP?" to find out all the ways to earn.
If you're not using SteemPlus yet, please check our last posts in here to see the many ways in which SteemPlus can improve your Steem experience on Steemit and Busy.

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!

Congratulations @amosbastian! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You made more than 14000 upvotes. Your next target is to reach 15000 upvotes.

You can view your badges on your Steem Board and compare to others on the Steem Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Vote for @Steemitboard as a witness to get one more award and increased upvotes!