How to Make a Ticket Bot

Ben Lahner
5 min readJul 20, 2024

--

Top of Mount St Helens’ crater, hike made possible by Ticket Bot.

TLDR; I explain how to make a ticket bot that checks for ticket availability every ~15 seconds and sends you a text and email when a ticket becomes available. I used this ticket bot to buy permits to climb Mount St. Helens. See the GitHub code here.

Introduction

Hiking an active volcano has long been on my bucket list. So when I spent a summer in Seattle, I set my eyes on hiking Mount St. Helens on the Fourth of July with a friend. As the date approached, however, I realized that the park service employs a permit system that sells out in mere minutes over a month before each date. There were zero permits available for the entire month, let alone July 4th.

Just when I thought all was lost, I saw a glimmer of hope: as I refreshed the permit availability page, I noticed spots sporadically opened and closed as hikers canceled their reservations and others bought them. Now I had hope that some permits might free up before the hike and I could snag some for my friend and I in time. But as much as I wanted to go on this hike, I just couldn’t dedicate the next week and a half refreshing the Mount St. Helens permit page. Enter, ticket bot!

In this post, I will walk you through how to make a ticket bot that automatically checks a website for ticket availability every ~15 seconds then sends you an email and text when a ticket becomes available. All code is available on my GitHub here.

So what actually is a ticket bot?

A ticket bot is simply code that automates exactly what you would do on a website. If you want a ticket bot to check for ticket availability on a certain date, for example, you would write code that navigates to the website, enters your desired date, and checks if your desired number of tickets are available — exactly the steps you would take.

Once the ticket bot sees that your desired number of tickets are available on your desired date, it can either complete the purchase for you (by again following the same steps you would take to complete the purchase) or notify you that the tickets are available. Here, I will show you how the ticket bot can send you an email and text notification when the tickets are available so you can manually complete the purchase.

Building your ticket bot

Since the ticket bot is going to automate everything we do, we naturally have to detail every step we would manually take to check for permit availability. In our example case of Mount St. Helens, the steps we (and the bot) would take are:

1. Navigate to the website URL in a browser

2. Enter number of permits you want (here, the ‘Group Members’)

3. Navigate to the correct month (here, ‘August’)

4. Check if permits are available for the desired day of the month (here, the 15th)

5. If permits are available: notify via email and text. If permits are not available: repeat starting with step 1.

Below is a pseudocode implementation:

# Imports
Import necessary libraries

Function check_permit_availability(group_size, month, day, year, url):
Log the current time
Setup and open a headless browser
Go to the provided URL
Wait for the page to load

Try:
Click the button to add group members
Catch error:
Log the error

Try:
If the desired month is in the future:
Click to change the month
Catch error:
Log the error

Format the desired date
Try:
Check if the desired date is available
If available:
Log availability
Send email notification
Catch error:
Log that the date is not available

Close the browser

Function send_email_notification(spots, date, url):
For each email address:
Send an email notification

Function main(args):
Schedule the permit check to run periodically

While True:
Run scheduled permit check
Wait for a short time to not overwork computer
If an email was sent:
Exit the loop

if __name__=='__main__':
Read the configuration file
Set up email details
Initialize logging
Initialize email_sent flag
Call main function with arguments

The trickiest part in this code is identifying the html element that corresponds with an action on a website, like clicking a button. To do this, we hover over the part of the website that we would normally click on, but instead of a left click, we right click and hit ‘inspect’. This shows us the corresponding html. In the python code, you now need to refer to this specific html element and manipulate it. There are several ways to refer to the html element, but I find using its XPath is easiest and least error prone.

As an example, below I show a GIF of finding the html element corresponding to clicking the “+” button to increase the Group Members. Notice how hovering over the html element highlights the corresponding part of the website. Below that is the corresponding Python code to automatically “click” that html element.

GIF of finding the html element that corresponds to an action on the website.
#open up chrome
options = webdriver.ChromeOptions()
options.add_argument('--headless') # Run headless Chrome. comment out to see the browser actually open.
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
driver.get(url)

#find the Group Member "+" button and click it
group_button_xpath = "//button[@data-component='Button' and @type='button' and contains(@class, 'sarsa-button') and contains(@class, 'sarsa-button-subtle') and contains(@class, 'sarsa-button-sm') and @aria-label='Add members']"
group_button = driver.find_element(By.XPATH, group_button_xpath)

for _ in range(group_size):
group_button.click() #click the plus button once

Putting it all together

You will need to write Python code similar to above for each part of the website you would manually “click” or manipulate. But once that is done, you can run your ticket bot and see how it checks for ticket availability every ~15 seconds just like you would!

This GIF shows the ticket bot automatically opening Chrome, navigating to the Mount St. Helens website, increasing the Group Members from zero to one, changing the month from July to August, and checking if there is availability on the 15th. Since there is no availability on the 15th, it closes the webpage and starts the process over again. If it had seen availability on August 15th, the bot would have sent you and email and text to notify you and closed out of the program.

Note that this ticket bot approach is pretty fragile. If the website modifies their html or implements some check to block automated visits, then you will have to find workarounds.

And please don’t abuse ticket bots…

Ticket bots are nothing new. Those who already know how to make them are already using them, and those who don’t know how to make them now have a great opportunity to learn a new tech skill that enables them to enjoy time outdoors or a night out with friends. Please don’t ruin someone else’s fun plans by buying more tickets than you need.

--

--

Ben Lahner

I enjoy tackling questions that appear impossible to answer. Current PhD student @MIT. Website: https://blahner.github.io/