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:

Screen Shot 2015-04-21 at 8.40.31 PM

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.

Screen Shot 2015-04-21 at 11.01.14 PM

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.

 

 

 
  1. Wake Up says:
    (link)

    “Reading this was like me trying to fit through a freezing cold needle eye, on a Carolina mountain top, wearing once used Buffalo hide” ~ Charlie Manuel

    All the best!

    • paul

      paul says:
      (link)

      @Wake Up: Your use of figurative language is commendable.

      • Wake Up says:
        (link)

        @paul: This is exponentially impressive, Charlie is just a bumpkin…

  2. CL says:
    (link)

    Razzball is now a clandestine spy agency?!

    • paul

      paul says:
      (link)

      @CL: Watch what you say.

  3. uncdrew says:
    (link)

    Me two stoopid

    • paul

      paul says:
      (link)

      @uncdrew: Sorry, man.

  4. Nate says:
    (link)

    Uhhh…. What?

  5. RotoLance

    RotoLance says:
    (link)

    Oh my. Love your comments section. I once scraped PFF (before they went paywall) and ESPN data to build my own football stats database… I used python.

    • paul

      paul says:
      (link)

      @RotoLance: Cool stuff, freakin paywalls…

  6. A Hill O' Beans says:
    (link)

    If it makes you feel better I was with you the whole way Paul! I can totally see the use in this, and as a former web developer I’ll take an API over scraping any day. I have looked into their API briefly though and backed away slowly as I tried not to make eye contact…

    And as Lance says, love the comments section in your posts, haha.

    • paul

      paul says:
      (link)

      @A Hill O’ Beans: Thanks A Hill. I understand some people are only interested in the final product, but when it’s said and done, the people who follow along now will appreciate it.

      • Joey says:
        (link)

        @paul: Glad you enjoyed it! More developments coming soon.

  7. Kevin says:
    (link)

    What about trying to go for a Current Roster Optimizer?

    Get your team, divide them into multiple categories based on eligibility, then based on handiness of pitcher facing + pitcher stats => generate best play on your team and post back to site with optimal roster?

    that’d be cool; I think.

    • paul

      paul says:
      (link)

      @Kevin: I agree, I think that would be a good intermediate step, and even a finished product in itself. I’ll give it a shot.

  8. Mike says:
    (link)

    I see you have reference to a key file. Can you explain a little more about what that is/does?

    • paul

      paul says:
      (link)

      @Mike: Yes I Can! The keyfile contains only two strings of text. One is called a ‘consumer key’, and the other is called a ‘consumer secret’. Both are given to you by Yahoo when you register for access to the API. Registering was surprisingly easy, it took only 5 minutes actually.

      • Rob says:
        (link)

        @paul:
        When you register for the API, Yahoo asks for a ‘Home Page URL’ and a ‘Callback Domain.’ I just want to run the scripts locally–what do I put for those two fields? (Even if I select ‘Mobile/Desktop’ for ‘Application Type,’ I still have to provide those two fields).

        • paul

          paul says:
          (link)

          @Rob: I put razzball as the application URL and a personal blog I have as the callback domain. I don’t think either of those sites are actually being used when I query the API, but I didn’t look into how that works. As far as I know, you can use anything.

      • Mike says:
        (link)

        @paul: Thanks, Paul. It looks kind of streamlined from what I thought it would be. Look at BaseballMonster, who uses/used the same interface to Yahoo’s API (I think). They ask if you want to connect to your Yahoo leagues, redirect you to a Yahoo login page, you put in your username and password, then you have to click a button that authorizes BaseballMonster to access your league info, then it pulls your Yahoo data into their setup for analysis. I assume they have some kind of keyfile like yours, but that one still had to jump through certain hoops during the actual pulling of data (like you are doing with this URL).

Comments are closed.