create account

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

View this thread on: hive.blogpeakd.comecency.com
· @amosbastian ·
$56.36
Adding the player vs. player command to my FPL bot for Reddit
<center>
![](https://i.imgur.com/ao1t2qN.png)
<br>
<sup>
https://github.com/amosbastian/FPLbot
</sup>
</center>

In [my last update](https://steemit.com/fpl/@amosbastian/adding-new-features-to-my-fpl-bot-for-reddit) 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).

<center>
![](https://cdn.steemitimages.com/DQmbyzdbUgVbkHHkUh4B8bATJNyF4ueYG8kfxLKhZqooLdq/image.png)
</center>

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:

<center>
![](https://cdn.steemitimages.com/DQmZp3AirVMLpr5zfMogXAfUw4k67v4bQpqe7nN9UgixSSJ/image.png)
</center>

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)

|xA|A|xG|G|MP|Fixture|Fixture|MP|G|xG|A|xA|
|-:|-:|-:|-:|-:|:-|-:|-:|-:|-:|-:|-:|
|0.13|0|0.42|1|**90**|Spurs 3-1 Leicester|Liverpool 3-0 Bournemouth|**89**|1|0.58|0|0.12|
|0.70|0|0.19|1|**90**|Spurs 1-0 Newcastle United|West Ham 1-1 Liverpool|**90**|1|0.64|0|0.00|
|0.00|0|0.20|1|**90**|Spurs 2-1 Watford|Liverpool 1-1 Leicester|**90**|1|0.18|0|0.10|
|0.38|0|0.05|0|**90**|Spurs 0-1 Man Utd|Liverpool 4-3 Crystal Palace|**90**|1|0.47|0|0.01|
|0.08|1|0.50|1|**77**|Cardiff 0-3 Spurs|Brighton 0-1 Liverpool|**90**|0|0.10|0|0.10|
|**1.29**|**1**|**1.36**|**4**|**437**|||**449**|**4**|**1.97**|**0**|**0.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](https://github.com/amosbastian/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
    
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](#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

<center>
![](https://cdn.steemitimages.com/DQmUereR9gc4Q4fTtadzzNVfmLXsLaMe3g6ozyPYRtzrpH4/image.png)
</center>

I've created a [Discord server](https://discord.gg/cjY37fv) 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.

👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 141 others
properties (23)
authoramosbastian
permlinkadding-the-player-vs-player-command-to-my-fpl-bot-for-reddit
categoryfpl
json_metadata{"community":"steempeak","app":"steempeak/1.7.2b","format":"markdown","tags":["fpl","utopian-io","development","football","opensource"],"users":["amosbastian","github.com"],"links":["https://github.com/amosbastian/FPLbot","https://steemit.com/fpl/@amosbastian/adding-new-features-to-my-fpl-bot-for-reddit","https://github.com/amosbastian/FPLbot/pull/4","https://github.com/amosbastian/fpl","https://#configuration","https://discord.gg/cjY37fv"],"image":["https://i.imgur.com/ao1t2qN.png","https://cdn.steemitimages.com/DQmbyzdbUgVbkHHkUh4B8bATJNyF4ueYG8kfxLKhZqooLdq/image.png","https://cdn.steemitimages.com/DQmZp3AirVMLpr5zfMogXAfUw4k67v4bQpqe7nN9UgixSSJ/image.png","https://cdn.steemitimages.com/DQmUereR9gc4Q4fTtadzzNVfmLXsLaMe3g6ozyPYRtzrpH4/image.png"]}
created2019-02-19 21:06:51
last_update2019-02-19 21:06:51
depth0
children6
last_payout2019-02-26 21:06:51
cashout_time1969-12-31 23:59:59
total_payout_value42.534 HBD
curator_payout_value13.823 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length5,120
author_reputation174,473,586,900,705
root_title"Adding the player vs. player command to my FPL bot for Reddit"
beneficiaries
0.
accountutopian.pay
weight500
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id80,115,991
net_rshares114,167,225,041,212
author_curate_reward""
vote details (205)
@helo ·
$10.97
- 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](https://join.utopian.io/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](https://review.utopian.io/result/3/1-2-1-1-1-1-1-).

---- 
Need help? Chat with us on [Discord](https://discord.gg/uTyJkNm).

[[utopian-moderator]](https://join.utopian.io/)
👍  , , , , , , , , , , , , , , ,
properties (23)
authorhelo
permlinkre-amosbastian-adding-the-player-vs-player-command-to-my-fpl-bot-for-reddit-20190221t150030565z
categoryfpl
json_metadata{"tags":["fpl"],"links":["https://join.utopian.io/guidelines","https://review.utopian.io/result/3/1-2-1-1-1-1-1-","https://discord.gg/uTyJkNm","https://join.utopian.io/"],"app":"steemit/0.1"}
created2019-02-21 15:00:30
last_update2019-02-21 15:00:30
depth1
children1
last_payout2019-02-28 15:00:30
cashout_time1969-12-31 23:59:59
total_payout_value8.334 HBD
curator_payout_value2.637 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length602
author_reputation121,547,934,535,311
root_title"Adding the player vs. player command to my FPL bot for Reddit"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id80,196,146
net_rshares20,553,789,137,952
author_curate_reward""
vote details (16)
@utopian-io ·
Thank you for your review, @helo! Keep up the good work!
properties (22)
authorutopian-io
permlinkre-re-amosbastian-adding-the-player-vs-player-command-to-my-fpl-bot-for-reddit-20190221t150030565z-20190223t183242z
categoryfpl
json_metadata"{"app": "beem/0.20.17"}"
created2019-02-23 18:32:42
last_update2019-02-23 18:32:42
depth2
children0
last_payout2019-03-02 18:32:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length56
author_reputation152,955,367,999,756
root_title"Adding the player vs. player command to my FPL bot for Reddit"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id80,294,798
net_rshares0
@steem-plus ·
SteemPlus upvote
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](https://steemit.com/@steem-plus) to see the many ways in which SteemPlus can improve your Steem experience on Steemit and Busy.
properties (22)
authorsteem-plus
permlinkadding-the-player-vs-player-command-to-my-fpl-bot-for-reddit---vote-steemplus
categoryfpl
json_metadata{}
created2019-02-20 07:26:21
last_update2019-02-20 07:26:21
depth1
children0
last_payout2019-02-27 07:26:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length438
author_reputation247,952,188,232,400
root_title"Adding the player vs. player command to my FPL bot for Reddit"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id80,133,894
net_rshares0
@steem-ua ·
#### 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](https://discord.gg/KpBNYGz)**
properties (22)
authorsteem-ua
permlinkre-adding-the-player-vs-player-command-to-my-fpl-bot-for-reddit-20190221t150620z
categoryfpl
json_metadata"{"app": "beem/0.20.18"}"
created2019-02-21 15:06:21
last_update2019-02-21 15:06:21
depth1
children0
last_payout2019-02-28 15:06:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length290
author_reputation23,214,230,978,060
root_title"Adding the player vs. player command to my FPL bot for Reddit"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id80,196,390
net_rshares0
@trufflepig ·
**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.](https://steemit.com/@trufflepig/daily-truffle-picks-2019-02-20) 
    
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!](https://steemit.com/steemit/@trufflepig/weekly-truffle-updates-2019-07)
    
Have a nice day and sincerely yours,
![trufflepig](https://raw.githubusercontent.com/SmokinCaterpillar/TrufflePig/master/img/trufflepig17_small.png)
*`TrufflePig`*
    
properties (22)
authortrufflepig
permlinkre-adding-the-player-vs-player-command-to-my-fpl-bot-for-reddit-20190220t163047
categoryfpl
json_metadata""
created2019-02-20 16:30:48
last_update2019-02-20 16:30:48
depth1
children0
last_payout2019-02-27 16:30:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length883
author_reputation21,266,577,867,113
root_title"Adding the player vs. player command to my FPL bot for Reddit"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id80,153,063
net_rshares0
@utopian-io ·
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](https://chrome.google.com/webstore/detail/steemplus/mjbkjgcplmaneajhcbegoffkedeankaj?hl=en) or [Steeditor](https://steeditor.app)).

**Want to chat? Join us on Discord https://discord.gg/h52nFrV.**

<a href='https://steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1'>Vote for Utopian Witness!</a>
properties (22)
authorutopian-io
permlinkre-adding-the-player-vs-player-command-to-my-fpl-bot-for-reddit-20190222t225239z
categoryfpl
json_metadata"{"app": "beem/0.20.17"}"
created2019-02-22 22:52:42
last_update2019-02-22 22:52:42
depth1
children0
last_payout2019-03-01 22:52:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length593
author_reputation152,955,367,999,756
root_title"Adding the player vs. player command to my FPL bot for Reddit"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id80,260,476
net_rshares0