FPLbot

April 5, 2019 · View on GitHub

FPLbot is a bot made for the subreddit /r/FantasyPL. It can also be used for other subreddits by changing the values in the configuration file.

Its current features are:

  • Posting the price changes of Fantasy Premier League players
  • Comparing the performance of a player vs. a team
  • Comparing the performance of a player vs. another player

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

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

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. All the data is taken from FPL's API & Understat. Here are two examples:

!fplbot heung-min son vs. mane 5

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

!fplbot rashford vs. liverpool

Rashford vs. Liverpool (last 4 fixtures)

FixtureDateMPGxGAxANPGNPxGKP
Liverpool 3-1 Man Utd2018-12-169000.0200.0000.020
Man Utd 2-1 Liverpool2018-03-107220.1700.0020.170
Liverpool 0-0 Man Utd2017-10-142400.0000.0000.000
Liverpool 0-0 Man Utd2016-10-177800.0000.0000.000
26420.1900.002.00.190

Configuration

OptionValue
USERNAMEThe bot's username
PASSWORDThe bot's password
CLIENT_IDThe bot's client ID
CLIENT_SECRETThe bot's client secret
USER_AGENTA unique identifier that helps Reddit determine the source of network requests
SUBREDDITThe subreddit the bot will post to
BOT_PREFIXThe prefix used to call the bot, e.g.: "!fplbot"

For more information about how to set up a bot see Reddit's guide.