Pickemfirst, a fantasy-sports assistant

We first came across Pickemfirst on our Fantasy Sports API Forum invitation to developers to show us their apps. This is a Guest Post post by Alain de Raynal, one of Pickemfirst's founders and developers, with assistance from Yohann Richard, the other founder/developer. If you're not sure what fantasy sports is, read this fantasy-sports Wikipedia article first. 

Let's start with some facts: More than 20 million people play fantasy sports in the United States. American football is by far the most popular fantasy sport. Yahoo! Sports is the #1 fantasy sports site. And Pickemfirst is your Fantasy Sports API assistant on steroids.

Pickemfirst screen

The idea

I started playing fantasy football and fantasy baseball in 2005. After a few years, I realized that the people who win at fantasy sports are usually the ones who pick the best free agents during the season.

There are thousands of websites that offer fantasy-sports advice, but none of them is able to tell you which player is a free agent in your own league. Therefore, scouting free agents is an extremely tedious and time-consuming task. It becomes even worse when you manage multiple teams.

I searched for software that would do some of the research for me but I could not find any. So, I decided to build my own solution: a tool that would automatically identify the fantasy league status of any player mentioned in the text of any article or blog on any web page.

I pitched the idea to my friend, Yohann Richard. It took us six months to create Pickemfirst, the ultimate fantasy sports assistant.

Since most fantasy sport activity is done on the web — managing the team, reading blogs, studying boxscores and game reports — it made sense to create a set of browser extensions. We currently offer downloads for Internet ExplorerMozilla Firefox, and Google Chrome. A solution for Safari is upcoming.

With a push of a button, color-coded icons appear next to players' names on any web page, telling the users if the player is already taken or if he is a free agent in their league(s). A click on these icons opens a pop-up window displayings news, statistitics, and more links to add the free agent to their fantasy team directly. See it in action in this two-minute video:

Here are some details on how Yohann and I proceeded with the development of the tool.

Accessing Yahoo's fantasy sports data

The first thing that we needed to do was access the fantasy data from Yahoo. This became much easier when Yahoo released their Fantasy Sports API in June 2010.

Since the Pickemfirst server is a Java web application, we started evaluating various Java OAuth libraries. We discovered Simpleyql  and fell in love with it.

The following first code snippet shows you how easy it is for a servlet to redirect users to the Yahoo pages where they will grant Pickemfirst the rights to access their fantasy profiles:


import com.simpleyql.Api;
import com.simpleyql.ApiFactory;
 ...

Api api = ApiFactory.getApiInstance(API_KEY, SHARED_SECRET,
                "http://app.pickemfirst.com/simpleyqlcallback/", false, null);
api.askAuthorization(request, response,
                 "http://app.pickemfirst.com/persistAuthdata");

Simpleyql manages the process of exchanging/refreshing tokens and authorizing users. The only thing our application needs to do is to store a single piece of information (authdata) for each authorized user. We do this within the second servlet (the one that maps to ”/persistAuthda”).


public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    String authData = request.getParameter("authdata");
    persistAuthdataInDatabase(authData); // our own method to store a token in the database
}

Once we have a hold of this token, it's very easy to run YQL query:


public static String queryYQL (String yqlStatement, String authData) throws IOException{
   Api api = ApiFactory.getApiInstance(API_KEY, SHARED_SECRET,
           "http://app.pickemfirst.com/simpleyqlcallback/",false, null);

   QueryResult qr = api.query(yqlStatement, authdata);
    if (qr.getAuthdata().equals(authdata) == false) {
        // persist the simpleyql token if it has changed.
        persistAuthdataInDatabase(qr.getAuthdata());
    }

  return qr.getText();
}

We use three types of YQL queries to retrieve the following data:

  • the leagues the user belong to: select * from fantasysports.leagues where use_login=1 and game_key=248
  • the teams the user manages: select * from fantasysports.teams where use_login=1 and game_key=248
  • the players on the all the teams in the league: select * from fantasysports.teams.roster where league_key='248.l.627060'

Building extensions for IE, Firefox, and Chrome

Our extensions include a set of JavaScript, CSS, and image files necessary to render the content on the client browser. The text processing is done in the client browser to minimize the load on our servers.

The JavaScript is composed of two parts:

  • The first part runs in a background page, and will persist throughout the user's browsing session. This code is responsible for fetching and caching data from our server.
  • The second part of our JavaScript code is injected in the currently viewed page, and is responsible for manipulating its content and displaying our popup window. 
    We chose jQuery  to get rid of crossbrowser compatibility issues.

The two JavaScript pieces of code talk to each other using mechanisms specific to the each browser. See the documentation about how to develop browser extensions (Chrome and Firefox) for more information.

What's next for Pickemfirst

Pickemfirst currently supports four different sports: Football (Pro and College), Baseball, Basketball, and Hockey. It can import fantasy teams from 10 differents websites (we found APIs for some of them; for others, we use screen scraping techniques). It aggregates the best news, stats, projections, and blogs.

All these features make Pickemfirst a very helpful and unique tool. But we're finding it difficult to generate more buzz because of two reasons: First, the non-commercial clauses of Yahoo's fantasy sports API prevent us from generating any kind of revenue, making it impossible for us to buy advertising. Second, most of the people who discover Pickemfirst want to keep it a secret. They don't want to tell their friends about the new secret weapon they use to beat them at fantasy sports...

About those commercial terms... Commercial terms are interesting. Given that we license our data from STATS LLC, our stats provider, we’re very limited by the terms of that contract for what we can offer in a commercial context. Our product managers and lawyers are actively working on figuring out what we’ll be able to do, but there is no definite timeline for when we’ll be able to truly support commercial access. We’re definitely trying our best, though! Keep checking the Fantasy Sports API Forum for updates. - Sean Montgomery, Yahoo! developer

Our main hope is that Yahoo Sports will soon create an app gallery to showcase the best apps developed with the fantasy sports API.

Here's hoping that being featured on the YDN blog is just a start! Send us email if you have any suggestions.

Alain de Raynal and Yohann RichardAlain de Raynal & Yohann Richard (@pickemfirst)
Founders and Developers of Pickemfirst