In December, I took a cross country journey and travelled over 2900 miles. The memories were invaluable, but the gasoline had a hefty price tag. Gas is expensive! And it would have been fantastic to know exactly where I could find the cheapest gas in the city. Sometimes the price varies as much as $0.50 per gallon. I might have saved $30 had there been a tool to find cheaper gas. Thus, my project will attempt to create a web application that shows exactly where one can find cheap gas in their city.
My objective for the project was to design and implement a web application that collects the lowest gas prices in Columbus, OH and displays them on a map. The prices will be updated daily to reflect the ten or fifteen lowest-priced gas stations in the city.
The first step I took toward accomplishing my objective was finding websites that already collect the gas prices at regular intervals. I quickly learned of GasBuddy.com, which has associate websites for some of the largest cities in the United States. Columbus' affiliate site is columbusgasprices.com which is the site I chose to use to collect my data.
I learned that gasbuddy.com already has mapped stations and their gas prices, but their map is not easy to find, clunky, and outdated looking, and not as simple as mine set out to be, so I still had a lot to work with.
My next step would be figuring out a way to grab the information from the columbusgasprices website and parse it into a usable format for my web application, and I needed it to update regularly.
I wrote a python script, which can be downloaded from my other server. In short, the script takes the raw hypertext from columbus gas prices and sorts through it to find the fifteen lowest priced gas stations for standard grade around Columbus. Let me break it down further.
I created a linux crontab, which is essentially a TaskScheduler, so that every 3 hours, the python script will run and the gas prices csv file will be updated to reflect the most current postings on Columbusgasprices.com. This coul be adjusted to any frequency down to the minute. I arbitrarily decided 8 updates a day would be sufficient.
My html file contains scripts for the leaflet, jQuery, and jQuery-csv libraries. One of my biggest complications through the whole project was that I could not run my python script in the gis.osu.edu web gis server. I had to create a new server (I used Amazon hosting). And then I had to figure out a method to implement cross-server AJAX, so that I could grab the data from the csv on another server and use it to generate markers for each gas station. Luckily, I found a work-around, but it compromises on security slightly. The jQuery-csv library allowed me to easily convert the csv file into a two dimensional python array. And I designed the script so that on a successful get request of the csv file, the fifteen markers of the fifteen lowest gas prices would be dynamically generated.
For the basemap I used a simple, elegant black-and-white map that makes it easy to see streets and the markers for gas stations clearly.
Overall, I think the project was grueling, but a resounding success. I feel comfortable scripting in python, and I was able to learn a lot about queries, APIs, and web protocols while building a practical tool that can be easily upgraded. And, the objectives I devised in my proposal were exactly met.