My first piece of advice to you is: Don’t do this…
Alright, now that we’ve gotten that out of the way, and seeing as how I have done this, let’s discuss. First off, you might be curious what access to the API gives you. You might even be curious what exactly an API is (still not sure). Or maybe you’re just wondering if that attractive co-worker of yours has ever hooked up with anyone in the office (she has).
To satisfy the first curiosity, Yahoo provides plenty of examples of what their fantasy sports API can give you. You can pull all the information about your league, the standings, each team, see who’s available, make (and reject) trades… basically everything a fantasy baseball bot should be able to do. For those of you just joining us, that’s the end goal here.
This console for testing YQL (Yahoo Querying Language) queries might be a better way to see all the data it makes available. For the link lazy, I’ll provide a small screenshot of what the output looks like:
Scintillating stuff, huh? All I’ll say is your computer thinks a photo of Kate Upton’s breasts is a sequence of 1’s and 0’s, so don’t judge something by it’s underlying data, and don’t judge me for getting a little excited when I see this stuff.
How it Works
I’ve learned my lesson, this section is not going to be a tutorial of how to use Yahoo’s API. Even if I wanted to, there’d be too many operating system/browser/computer-specific issues, that I doubt I could make an effective one.
What I’ll say is, this was a gigantic struggle for me. I grayed a little, lost sleep, and spent countless hours indoors on two of the nicest weekends this year. While I am being a bit dramatic and this “update” on my “progress” might seem underwhelming to some, when I finally saw my code pull results instead of an error message on Monday night, the satisfaction was real.
Ninty-nine percent of the code I’m using is from this glorious python-yahooapi repository. All I had to add were these measly six lines of code to get it to pull the league data in the first screenshot.
Obviously there will be a lot more to it when I’m downloading all the information about a league; I was happy just to get the damn thing to work.
So the next step is downloading all the data about a league (I’ll be using the infamous Yahoo Friends & Family league) and parsing it into some sort of digestible format. I’ll get started on that and hopefully will have an update next week in part 2 of 1000.
A Quick Shoutout
If you’ll let me indulge, I’d like to say thanks to reader/commenter Kevin, who cleaned up my auction simulation code and added some functionalities to it as well. While that project is on the back-burner for now, I’m still optimistic there are things to be learned from it. I’ll pick that fight another day.
Using the API vs Scraping the Data
When I first envisioned the fantasy baseball bot, I assumed I would be web scraping the data that serves as its input. This obviously is not the case anymore. As much as I despised the API when trying to get it to work (the process is needlessly complex) it’s benefits are slowly becoming more and more apparent. Mainly, I just think the API gives the data more efficiently than scraping can, and the built-in functionality to add/drop players, set your lineup, and evaluate trades is perfect for the bot.
The downsides are it’s limited to Yahoo leagues (why are the RCL’s on ESPN again?), it is harder to use in other ways, and I don’t like being dependent on Yahoo to maintain it. Will I go back an try to also make a version of the bot that works on scraped data? Maybe, but for now I’m going to try to utilize the API for all it’s worth.
Other Uses for this League Data?
At some point in the future I’ll be downloading, every single day, a wealth of data about my league. The standings, the players on each team, the stats those players produced, and so forth. This has me thinking there are probably other potential uses for this data.
One idea is to create a productivity metric for each roster spot. While anyone who spends five minutes looking at his roster has an idea of how much production he’s getting from each position, it wouldn’t hurt to be able to have an exact figure, in either absolute (35 homers from your 1B slot) or relative terms (first in your league).
In daily-move leagues where there’s high roster turnover, having this information on your opponents could help you understand how they are using their roster to maximize production, without having to check their lineups everyday.
I’d also imagine Rudy would have a field day in the offseason making posts like this if this data was available from all the RCL’s. Not sure if that’s an unhandleable amount of data.
Thinking more grandly, you could also use this data to build a “Custom League Suite” that houses a whole host of information and graphs about your league. While ESPN and Yahoo are nice, I’m sure if you were told you could design what your league interface looks like from scratch, you would pick something a little different. In what’s probably my personal favorite thing I’ve written for Razzball, a short story called “The Ideal Fantasy Manager” (tucked in at the end of that article from last year), I mention the idea of this kind of League Suite. The seeds have been sown for this idea for a while, I suppose.
Overall, my point is there’s a lot of information being generated by our fantasy leagues that we’re letting, for the most part, slip through our grasp. I’m just trying to use it.