LOGIN

Last article, I introduced pulling your league’s data from Yahoo’s API in a Python script. Today, I’m going to show you a better way to do that very same thing.

In my last article dkempiners’ python-yahooapi code was used to do the heavy lifting, but admittedly I didn’t have a great understanding of how it worked and it was clunky in ways. This week we’re going to use josuebrunel’s myql code base, which at least for me was cleaner to use and easier to understand.

Since it seemed like more than a few people tried to follow along and do it themselves last week, this article will simply show how to use it, but won’t go anywhere near a step-by-step level of detail. Some coding knowledge is expected, in other words. If you have questions, I’ll do my best to answer them.

 

The Quick n’ Dirty Tutorial

So, download the code, install the necessary packages yada, yada. The Readme file for the repository is pretty helpful for getting set up.

The biggest thing you have to do to get the code working is save a .json file with your consumer secret and consumer key stored in it. I had never used a Json file before but after a little old fashioned trial-and-error, I figured out the format of such a file looks something like this:

Screen Shot 2015-05-05 at 9.04.27 PM

 

Save that as credentials.json in wherever your working directory is. After that, there isn’t much else you have to do to the code to get it to work. If the amount of files overwhelms you a little, all the action occurs in ‘myql.py’ and ‘yoauth.py’.

Skipping straight to the end, running the following lines of code pulls the same Friends and Family league data we did last week:

Screen Shot 2015-05-05 at 9.58.24 PM

Overall I think this is a much cleaner way of accessing the API in the way the response variable is  built in the format of a SQL query on the fantasysports.leagues table with the league key I specified. This package even has some cool features like opening your browser automatically to get the verifier and storing your access token in the same credentials.json file after you get the code to work once.

These words should make sense to anyone who tries to do this, I promise.

 

Looking Ahead

I still have no idea how to parse the json (or XML) output from the API, so that’s the next morsel on my plate of knowledge. I also have to start building/designing what I’ll call the warehouse architecture to store all this league data.

CSV files? Txt files? Open the data in R or Excel? No, definitely not Excel. Make a whole SQL or other type of database? What is Hadoop anyway?

That’s what my mind looks like right now.

I’ll experiment with different things, but if anyone has experience in these sorts of matters, please feel free to chime in. I’m not afraid to throw my hat into the “big data” ring, which is a nice term for impressing your single 35 year old boss, but I’m also not convinced it is necessary.