A fun little project combining two of my new favourite hobbies. Yahoo Fantasy Basketball and Selenium browser automation. After I tragically forgot to set my lineup this week I went about building a python program that would do it for me so this travesty would never happen again.
The nba-start-active-players-bot is a python script that logs into your Yahoo fantasy basketball account and starts all active players for today and upcoming days.
When you run the script it will ask you for your Yahoo username, Yahoo password, the number of days you would like the bot to process into the future and whether you want to see what the browser is doing while it's running.
You can even pass it command line arguments to save time or help with scheduling the running of the script. For example, to start active players for the next week including today you would run the script like this:
python start-active-players.py --days=7 --username=YahooUsername@yahoo.com.au --password=Y0urYah00Passw0rd --headless=True
The script uses Click to manage the command line interface and handle the options passed to the script.
At its core the python script uses Selenium WebDriver a browser automation framework often used for automated QA testing. It is currently configured to use ChromeDriver for normal mode, or PhantomJS (ghostdriver) for headless mode. However, it could be easily edited to launch webdriver's default browser firefox instead.
Firstly the script enters your credentials in order to log into the Yahoo basketball portal. Once inside it navigates to the My Team page and clicks the 'set active players' button for today. At this point it begins a loop, clicking the 'next day' button and then clicking the 'set active players' button again. It does this for as many days as the user has specified.
Once it has processed the correct amount of days it will close the browser session.
I have a few more upgrades I still want to make to it, they have been listed on the github page.Project on Github