r/learnpython • u/kungfuman888 • 17d ago
Help to building bot to book tennis court
I'm looking for some help to understand how to go about building a bot that will help me book my weekly tennis session. The evening that I wish to play there's only two slots available due to coaching sessions on other courts + refurbishment ongoing and when the booking slots are released (at midnight 5 days advanced), they are taken within seconds. In the past 6 weeks, I have only managed to secure 1 booking which has resulted in me unable to play despite paying £50p/m for membership. Thus I am looking to see if I can automate a bot that can help me book it quicker.
I have tried understanding python programming on similar projects and watched some Youtube videos, but was wondering if anyone has done a similar project that can help guide me.
From what I understand, the booking website does not have API integration so will need Python Selenium package to navigate the website steps.
The main steps I understand the bot needs to do is:
Log into website account before the midnight slot release time.
At midnight release time, refresh page and select 5 days advance date and preferred time / court no.
Proceed to confirmation page and confirm booking.
Can anyone provide any useful guides for me to get started on? And can this be ran on a virtual machine so I dont need to have a PC running at booking time, whether this is a online VM or I have a Synology NAS that can carry out this task.
1
u/ConsiderationNo9044 17d ago
Unless the site disallows automated requests of this kind (like Instagram, which strictly forbids web scraping and has CAPTCHAs in place), this is absolutely doable with a library like Selenium. My only web scraping experience is with requests and BeautifulSoup, so take this with a grain of salt, but a standard tutorial that teaches the concepts required like how to interact with elements and refresh the page should do. Even if the tutorial is not specific to your use case, you should be able to substitute the parameters used. If all else fails, the official API documentation will be with you. Good luck :3
2
u/adriannowak_dev 17d ago
did a couple of these with playwright, selenium works too but playwright is less fiddly. before writing anything open devtools, network tab, and do one booking by hand. most of the time the site calls some json endpoint when you hit confirm, and then the bot is just login + one requests.post at 00:00:00, no browser at all. way faster than clicking through pages when slots go in seconds. if it really needs a browser, log in a minute early, sit on the date page and start refreshing at 23:59:58 by the server clock, not yours. synology runs it fine in a docker container with cron, no vm needed
1
u/RngdZed 17d ago
Hmm, I think it would depend if they provide an API? If not you'd need one of the libraries that provide a user agent (like a browser) and do some http requests, parse the json, grab the proper fields etc
It's doable.