Let me start this post with a brief preface. If you are not a baseball fan who is interested in baseball statistics, this post will probably not hold much interest for you. However if you are, then you may be familiar with the MLB Gameday application and its data which is a great source of richly detailed MLB statistical data. This post will show you how to take that data from the MLB server and put it on your local machine for easier use, using the Gameday API.
Many users of the Gameday like to download the data files to work with them locally. Currently most people use a rather complex Perl script to download the Gameday XML data files. In this post I will show you how you can use the Gameday API to easily download some or all of the available data from the MLB Gameday servers.
This post assumes you know enough about Ruby to understand what the IRB console is. IRB is an easy to use interactive Ruby shell. For those who are not familiar with IRB, here is a tutorial that should get you started. To get started with downloading the Gameday data files, open up an IRB shell inside of the lib directory of the Gameday API. At the IRB prompt type this:
downloader = DataDownloader.new
And thats it! The first line imports the required Ruby class into your IRB session. The second line creates an instance of the DataDownloader class for you to use. The third line calls the download_all_for_month method which will start the download process. All of the Gameday files for the month of May in the year 2009 will be downloaded to your local file system. The files will be placed in the lib/components directory in your Gameday API folder with the lower level directory structure on MLB Gameday preserved. This will not happen instantly, it will take some time to download the entire month of game data.
Hopefully this will make it easier for some who have wanted to play with the Gameday data but felt intimidated by the Perl scripts that are around. As always, if I can help you out in anyway don’t hesitate to contact me. The best way these days is probably through Twitter, @tfisher.