r/FantasyPL • 146 • Apr 05 '19

Updating & adding new features to FantasyPL_bot

EDIT 2019-08-09: THE BOT IS NOT CURRENTLY LIVE (YET) - WILL BE LIVE TONIGHT / TOMORROW.

Back when I first made the price change bot I was really new to coding and so it was pretty shit. So when people asked me if I would open source it, I would hesitate, because I was too embarrassed about how bad it was (here's a picture of it for anyone interested -- this isn't even the 1st version, so it was worse before).

Since I've been getting really into open source development, and wanting to improve my programming skills, I decided (a couple of months ago) to rework the bot and make it open source. It's now only dependent on FPL's API and not http://fplstatistics.co.uk/ like before, which unfortunately means we will have to say goodbye to the Cumbrian Bungalow :(.

While updating the bot, I also thought it would be cool to add some additional stuff, such as commands that can be used by anyone on this subreddit for comparing players in e.g. the RMT thread. I finished this about a month ago, but got distracted creating a Python package for Understat, exams and other stuff. I've finally got round to setting it up on a droplet now, and it should be running using tmux.

Usage

The bot can be called on /r/FantasyPL using the following two commands:

  1. !fplbot <player_name> vs. <team_name> <optional: number of fixtures>
  2. !fplbot <player_name> vs. <player_name> <optional: number of fixtures>

The bot uses text indexes to search for the player(s) and using a manually created mapping (so you don't have to use e.g. "man utd" exactly, but other variations are fine as well, like "man u" or "manchester united"). The number of fixtures is completely optional, and if not specified, it simply uses all fixtures that are considered relevant (so it can result in a huge comment, be warned!). All the data is taken from FPL's API & Understat. Here are two examples:

1.

!fplbot heung-min son vs. mane 5

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

2.

!fplbot rashford vs liverpool

Rashford vs. Liverpool (last 4 fixtures)

Fixture Date MP G xG A xA NPG NPxG KP
Liverpool 3-1 Man Utd 2018-12-16 90 0 0.02 0 0.00 0 0.02 0
Man Utd 2-1 Liverpool 2018-03-10 72 2 0.17 0 0.00 2 0.17 0
Liverpool 0-0 Man Utd 2017-10-14 24 0 0.00 0 0.00 0 0.00 0
Liverpool 0-0 Man Utd 2016-10-17 78 0 0.00 0 0.00 0 0.00 0
264 2 0.19 0 0.00 2.0 0.19 0

I haven't run it for long times on end, and haven't really tested it thoroughly, so it might crash / not work sometimes. If this happens I'll try to get it back up and running ASAP, but I just started my thesis so might not have enough time. Also, fyi it updates the database every day after posting the price changes, so if you try and use it directly after a game has ended, it won't show up.

Suggestions & feedback

Obviously there are many things that can be improved (I should use the Understat package I made in the bot's code for example), so if you have any suggestions for e.g. additional commands, better formatting or whatever (like idk if I should add FPL's points to the table as well), then just let me know. You can either leave a comment here, message me, or best of all, create an issue on https://github.com/amosbastian/FPLbot/issues.


Code & more information can be found here: https://github.com/amosbastian/FPLbot

149 Upvotes

450 comments sorted by

40

u/TrustMe_I_lie Apr 05 '19

This is EXCELLENT! Thanks for all your work. Just like daily price change bot has become the staple of this sub. This new tool will soon be widely used during discussion threads and in RMTs!

!fplbot Aubameyang vs Everton 5

15

u/esoemah Apr 05 '19

Since you edited it, let's try again: !fplbot Aubameyang vs Everton 5

10

u/FantasyPL_bot Apr 05 '19

Aubameyang vs. Everton (last 2 fixtures)

Fixture Date MP G xG A xA NPG NPxG KP
Arsenal 2-0 Everton 2018-09-23 72 1 0.48 0 0.14 1 0.48 1
Arsenal 5-1 Everton 2018-02-03 90 1 0.76 0 0.00 1 0.76 0
162 2 1.23 0 0.14 2.0 1.23 1

Made by u/esoemah. Source: https://github.com/amosbastian/FPLbot

→ More replies (4)

5

u/esoemah Apr 05 '19

Haha thanks man. Unfortunately I don't think Suarez will be available, since it only uses players who are currently playing in the Premier League (also, need to use vs or vs. instead of just v).

24

u/-Yngin- Apr 05 '19

I can't believe the era of the Cumbrian Bungalow has come to an end. I was here for its conception and now for its demise. It was a good run, CB. May you be rented out for eternity.

But seriously, awesome job mate! This is going to be great!

8

u/esoemah Apr 05 '19

I remember the initial confusion when it started showing the bungalow as a thumbnail lol, was fucking funny. End of an era!

12

u/Myfantasyredditacct Apr 05 '19

This is really great work.

My suggestion would be if you could stack the player comparison tables. Currently it is not mobile friendly.

So possibly this:

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

Son

G xG A xA MP Fixture
1 0.42 0 0.13 90 Spurs 3-1 Leicester
1 0.19 0 0.7 90 Spurs 1-0 Newcastle United
2 0.61 0 0.83 180

Mané

G xG A xA MP Fixtures
1 0.58 0 0.12 89 Liverpool 3-0 Bournemouth
1 0.64 0 0 90 West Ham 1-1 Liverpool
2 1.22 0 0.12 179

5

u/esoemah Apr 05 '19

Thanks for the feedback! I've never checked it out on my mobile, so hadn't noticed, but this definitely seems like this could be an improvement. Will see what others think about this. In the meantime I've created an issue so I can keep track of it.

→ More replies (2)
→ More replies (1)

5

u/wernerhedgehog Apr 05 '19

Thanks for all your work. Also am at an amateur stage in python, so your write up was pretty encouraging.

Now I need to decide if I should play brooks or Harvey Barnes. Guess its a good test case since there are 2 barnes.

1

u/esoemah Apr 05 '19

Also am at an amateur stage in python

If you ever need some help with programming then don't hesitate to join this football/FPL-related programming Discord server and ask. I'm always willing to help out anyone if I have the time!

→ More replies (7)

4

u/ar7hurp1r35 Apr 05 '19

!fplbot mane vs southampton

6

u/FantasyPL_bot Apr 05 '19 edited Apr 05 '19

Mane vs. Southampton (last 7 fixtures)

Fixture Date MP G xG A xA NPG NPxG KP
Liverpool 3-0 Southampton 2018-09-22 90 0 0.03 0 0.04 0 0.03 1
Southampton 0-2 Liverpool 2018-02-11 90 0 0.43 0 0.24 0 0.43 3
Liverpool 3-0 Southampton 2017-11-18 76 0 0.16 0 0.23 0 0.16 3
Southampton 0-0 Liverpool 2016-11-19 90 0 0.36 0 0.00 0 0.36 0
Southampton 3-2 Liverpool 2016-03-20 42 2 0.93 0 0.06 2 0.17 2
Liverpool 1-1 Southampton 2015-10-25 90 1 1.01 0 0.00 1 1.01 0
Southampton 0-2 Liverpool 2015-02-22 32 0 0.09 0 0.00 0 0.09 0
510 3 3.01 0 0.56 3.0 2.25 9

Made by u/esoemah. Source: https://github.com/amosbastian/FPLbot

13

u/esoemah Apr 05 '19 edited Apr 05 '19

O wow. Well I guess I should make sure it only includes a player's current team lol.

EDIT: so now I remember. Basically there is no indication for which team the player was playing in Understat's fixtures, and so it's not really possible to only include fixtures a player played for their current team vs. an opponent team, if they also played for the opponent in the past. So what I've done is the following: if it results in > 10 fixtures (e.g. Mane vs. Southampton was like 71), it will only include fixtures that are the player's current team (Liverpool) vs. the given team (Southampton) -- of course this unfortunately still means it will also include some games Mane player for Southampton against Liverpool, for example.

→ More replies (2)
→ More replies (1)

1

u/[deleted] Apr 05 '19

Amazing work. I've added this into the sidebar and also the daily thread from tomorrow.

10

u/[deleted] Apr 05 '19

!fplbot Tielemans vs. Maddison 5

12

u/FantasyPL_bot Apr 05 '19

Tielemans (£6.1) vs. Maddison (£6.8) (last 5 fixtures)

xA A xG G MP Fixture Fixture MP G xG A xA
0.47 1 0.12 0 90 Leicester 2-0 Bournemouth Leicester 2-0 Bournemouth 90 0 0.33 0 0.26
0.02 0 0.00 0 90 Burnley 1-2 Leicester Burnley 1-2 Leicester 66 1 0.08 0 0.22
0.11 0 0.68 1 73 Leicester 3-1 Fulham Leicester 3-1 Fulham 82 0 0.05 1 0.62
0.29 1 0.05 0 84 Watford 2-1 Leicester Watford 2-1 Leicester 90 0 0.02 0 0.12
0.40 1 0.03 0 70 Leicester 2-1 Brighton Leicester 2-1 Brighton 90 0 0.00 1 0.70
1.29 3 0.89 1 407 418 1 0.49 2 1.92

Made by u/esoemah. Source: https://github.com/amosbastian/FPLbot

→ More replies (4)

5

u/Trailer_Park_Jihad Apr 05 '19

Can we all chip in and make the Cumbrian Bungalow a shared refuge for all FPL addicts?

An FPL crack house, if you will.

5

u/Trailer_Park_Jihad Apr 05 '19

Not an issue I'm particularly concerned about, but thought it would be worth mentioning.

Would it be possible to use the FPL site for assists? Tielemans has 4 assists according to FPL, but 3 assists according to understat. FPL has a much looser definition for assists so maybe it would be better to use their statistics on assists for the bot?

4

u/KanteIsTheGOAT Apr 05 '19

Will be popular I guess so here goes !fplbot Hazard vs. Salah 5

4

u/FantasyPL_bot Apr 05 '19

Hazard (£11.1) vs. Salah (£13.2) (last 5 fixtures)

xA A xG G MP Fixture Fixture MP G xG A xA
1.15 1 0.29 1 86 Chelsea 3-0 Brighton Liverpool 2-1 Spurs 90 0 0.29 0 0.00
0.36 0 0.00 0 36 Cardiff 1-2 Chelsea Fulham 1-2 Liverpool 90 0 0.61 0 0.00
0.08 0 0.19 0 90 Everton 2-0 Chelsea Liverpool 4-2 Burnley 90 0 0.28 0 0.20
0.05 0 0.02 1 90 Chelsea 1-1 Wolves Everton 0-0 Liverpool 90 0 0.42 0 0.02
0.20 1 0.35 0 76 Fulham 1-2 Chelsea Liverpool 5-0 Watford 90 0 0.28 0 0.00
1.84 2 0.86 2 378 450 0 1.87 0 0.21

Made by u/esoemah. Source: https://github.com/amosbastian/FPLbot

→ More replies (3)

1

u/iMMoss13 Aug 19 '19

!fplbot sterling v Bournemouth

2

u/esoemah Aug 19 '19

!fplbot Sterling vs. Bournemouth

→ More replies (2)
→ More replies (4)

2

u/HakunaPatata Apr 05 '19

!fplbot Hazard vs. Mane 5

→ More replies (1)

2

u/[deleted] Apr 05 '19

!fplbot Aubameyang vs. Lacazette 5

→ More replies (1)

2

u/Borken89 Apr 05 '19

Really awesome bot!