BACKGROUND // After moving to the Bay Area, I was excited to be so close to Yosemite, which hosts some of the best rock climbing in the world. But what I didn't realized until climbing season came around was that getting a campsite in Yosemite Valley is near impossible. While in the Valley, I talked with a Park Ranger who explained that campsites are released to the reservation website 6 months prior to their reservation date and are filled almost immediately. When people cancel their reservations, it gets kicked back onto the website and becomes available to the public, but is usually picked up again in 15 minutes by someone sitting at their computer hitting refresh on their web browser periodically. But according to the Ranger, this is the best way to try and get a campsite. Of course, as soon as my roommate Drew and I heard this, we thought 'There must be a way to automate the monitoring process so we can know the moment those sites become available...'.

OBJECTIVE //  Write a program to monitor the Yosemite Campsite Reservations website to alert me to campsite availabilities when they enter the system.

INGREDIENTS //

……………(1)   PHP script

……………(2)   Python script

TECHNICAL // The project centered around a PHP script that scraped the websites of each individual campsite to determine when their next available date is. Each individual site has a code that is used to identify it and track which dates have been booked. The website also uses a search function that allows the user to look for the next available date for a specific site. So I compiled a list of all the site codes and then cycled through each of them, requesting the contents of the html page that was produced when the search function was called.

When the contents of each page is returned, I cycle through the verbose, formatting text and search for the phrase 'There are no available dates for this campsite.' If this isn't found, then I know that there is a site available and if I could see the page, they would be listing the next available date. After looking for patterns in how the available dates where formatted across the successful responses, I noticed that the first available date is a clickable link and when you click on the link, it passes the date you clicked through to the booking page. This provided the key phrase that prefaced the date that we needed to extract from the page.

Now, with a list of all the available campsites, we need to determine whether the discovered sites are new since the last time the script sent out an alert, so that we aren't getting an email every minute until a campsite is gone. I had the script save the sites and dates to a text document, so that the next time the script ran, it could cross reference the list and mark only the new dates to be delivered. Once it compiled a list of all the new available reservations, it composed an email from a special GMail account and sent all the new sites/dates with hyperlinks, to me and Drew via email, as well as with a SMS alert.

In order to kick off the PHP script, I wrote a very quick and simple program in Python to request the PHP page and then pause for a minute before repeating. This allows me to only run it when I am looking for a campsite.

RESULT // This turned out to be surprisingly effective. After piloting the php script on Monday, we had a campsite by Tuesday for that Saturday! I was even able to get a coworker a campsite for Memorial Day weekend, just two weeks away!

 

NOTES // Recreation.gov seemed to be surprisingly open with their data, publishing the following disclaimer on their website:

You are invited to use the data on this website in your publication/website/computer system, and to get updates and refresh your website often via Recreation.gov. We request that you provide credit and a link to Recreation.gov in exchange.

Recreation.gov includes information on Federal government managed and Federal government affiliated (subordinate, subsidiary or member) sites. It does not list hotels, restaurants, or tourist attractions managed by private companies or other organizations. Our content focuses on nature-based, historic and cultural activities commonly available on federally managed lands.

The data in Recreation.gov is provided for free - there is no cost to use it, and no need to contact us before incorporating Recreation.gov data into your system. (In exchange, we encourage you to provide a link to Recreation.gov and acknowledge credit, such as Data Source: Recreation.gov)