Adding the player vs. player command to my FPL bot for Reddit

in #fpl5 years ago






https://github.com/amosbastian/FPLbot

In my last update I laid the groundworks for the entire bot and also added a player vs. team command. With this update I've now added another command that allows users to compare a player against another player (and some other improvements here and there).

https://github.com/amosbastian/FPLbot/pull/4

The new command

The new player vs. player command works the same as the player vs. team command; !fplbot <player_name> vs. <player_name> <optional: number of fixtures>. However, there are some differences, mainly because of the fact that there is too much interesting information available. In the player vs. team table you could show all of this, but when comparing two players, it would be too much to add all this to a Markdown table. Because of this, I've decided to simply compare each player's goals and assists (and their expected values).



The first function that was created was versus_player_handler(). It basically gets all information it needs; the players (using text indexes) and their relevant fixtures (all the fixtures the player has played for their current team). It then zips these fixtures together (since you want to compare the two) and sends it to another function to create the Markdown table.

The table

In the end I created the player_vs_player_table() function, which in itself is a bit big (and maybe messy), but it works. As I mentioned before, it strips the information contained in the player vs. team table and creates something like the following table:



It could also be used on Steemit itself, but honestly I don't think the Markdown tables look anywhere near as good on here (although on Steempeak they do):

Son (£8.9) vs. Mané (£9.6) (last 5 fixtures)

xAAxGGMPFixtureFixtureMPGxGAxA
0.1300.42190Spurs 3-1 LeicesterLiverpool 3-0 Bournemouth8910.5800.12
0.7000.19190Spurs 1-0 Newcastle UnitedWest Ham 1-1 Liverpool9010.6400.00
0.0000.20190Spurs 2-1 WatfordLiverpool 1-1 Leicester9010.1800.10
0.3800.05090Spurs 0-1 Man UtdLiverpool 4-3 Crystal Palace9010.4700.01
0.0810.50177Cardiff 0-3 SpursBrighton 0-1 Liverpool9000.1000.10
1.2911.36443744941.9700.34

Once this table has been returned to the versus_player_handler() function, the comment is formatted with its header (the Son (£8.9) vs. Mané (£9.6) (last 5 fixtures) bit) and the table as its body, and then the bot replies to the comment that requested it.

Some small improvements

I've also added the player's price to the player vs. team table, as that is a pretty important aspect of the Fantasy Premier League. I've also slightly improved the regex, as I noticed that it wasn't picking up diacritics, which meant that e.g. "son vs. mané" was seen as "son vs. man".

Other than that I've added a separate script for initialising the database. Since it uses text indexes to search for the players in the database, of course they need to be made first. Finally, I also added a simple script for posting the price changes, so I can use that in the cron job instead of bot.py.

Roadmap

I will be making a post about it on Reddit and will see what people want to see, and if they want anything that has already been implemented to change. Hopefully they come up with some good ideas!

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 [email protected]:amosbastian/FPLbot.git
cd FPLbot
pip install -r requirements.txt

To initialise the database with text indexes you should do the following:

python FPLbot/init.py

Once this has been done, you should create your own config.json with the correct values (see configuration).
With this filled in, you can run the bot using

python FPLbot/bot.py

As for the price changes, you should schedule a cron job, like this for example:

25 1 * * * /home/amos/FPLbot/venv/bin/python /home/amos/FPLbot/FPLbot/price_changes.py

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.

Sort:  
  • Great post with lots of images, instructions and code sample.
  • Code looks good with lots of comments and great separation of concerns on the commits.

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, @helo! Keep up the good work!

Hi, @amosbastian!

You just got a 0.07% 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.

Congratulations! Your post has been selected as a daily Steemit truffle! It is listed on rank 7 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 5 SBD worth and should receive 115 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
TrufflePig

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

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!

Coin Marketplace

STEEM 0.18
TRX 0.14
JST 0.029
BTC 57899.47
ETH 3134.16
USDT 1.00
SBD 2.39