Finding Campsites with Python
My wife and I love to camp on the Oregon coast and the summer is always the best time to go. It also ends up being the most competitive time to find a campsite.
If you look up the handful of good campsites on the coast you will probably find that nearly every summer weekend is booked months in advance. This makes it really hard to go camping! This is what a typical summer weekend looks like on Reserve America:
Without having to book months in advance or check the site 24/7, I wanted a way to be able to reserve the best campsites at our desired campground.
My first thought was to look at Reserve America’s availability notifications feature. It’s supposed to email you when a site and date that you want is canceled and becomes available. Unfortunately, this feature doesn’t seem to work reliably and when it does, it doesn’t notify you until around 5 am the next day – usually too late to reserve.
I thought it would be simple enough to write a script that scrapes the reservation site and tells me if any one of my desired campsites were available on specific dates. Lucky for me, the Reserve America site has very little protections in place and is extremely easy to scrape.
Using Beautiful Soup for parsing HTML and Mechanize for filling out the web forms, I got it working in a few lines of Python. It took a few more tweaks to make it work reliably and I ended up with something like this:
By throwing this code into a loop that goes through all the dates I wanted, I had a reliable way to check for campsite availability. I decided to use python’s own SMTP library as my notification method and I plugged in the credentials of an old gmail account.
After figuring out an authentication issue with gmail (with the help of this SO answer), I was sending notification emails and everything was working great. My next step was to set it up to run on a regular interval.
I recently tried out DigitalOcean, the popular virtual private server (VPS) service. For just $5/month, you get an awesome easy-to-use server that you can access from anywhere. Minutes after signing up I had a working accessible server up and running. I copied my script up to my new VPS, set up a simple cronjob to run my script every 15 minutes, and I was good to go.
In case you didn’t notice, I highly recommend DigitalOcean. Sign up with this link and you’ll get a free 2 months.
I also use a free service called Dead Man’s Snitch to monitor my cron jobs. DMS alerts you if your job stops running and gives you a convenient dashboard to easily see what’s running and what’s not. I highly recommend it.
After just a few days of deploying the script, I got a notification of a great campsite that my wife and I had wanted to stay at for years. Just a week after that, I got another email telling me that the two best sites in the campground were available on the weekend we wanted. It seems to be working quite well!
I’ve been told that Reserve America no longer handles California State Park reservations. I do not think this script is compatible with the new Reserve California system. Sorry!