Now we do some plots. New comments cannot be posted and votes cannot be cast, More posts from the fantasyfootball community, /r/fantasyfootball - Good For Your Season, Press J to jump to the feed. CAVEAT: your league needs to be “public”, or you need to figure out how to send session cookies or login remotely, see end of this post. ESPN has an accessible, though undocumented, API for their Fantasy football database. Find the best projected stats of the 2020 NFL season and build the best Fantasy Football team. However, it only returns the full information if you are logged into an account, which I’ve been unable to do through a GET request. Let’s focus on the matchup scores and plot some low-hanging fruit. Here’s how to grab historical projections, 2 - Peeking under the hood with a linear model, 1 - AI and Machine Learning: the big ideas, Measuring Roster Skill in Fantasy Football, Scraping Pro Football Reference with Python, Checking ESPN Fantasy Football Projections with Python, Clustering NFL Wide Receivers by Individual Play Distributions, Anything you can do, I can do (kinda). If you’ve cracked the code on this, please let me know. In Chrome, you can go to Preferences -> Advanced -> Content Settings -> Cookies -> See all cookies and site data, and look for ESPN. There's an additional code I found to add so it comes up on all pages not just the league home page... On mobile now but I'll try to reply later. Here’s several that I know about: Each of these can be appended to the ESPN API URL and be explored. Here’s a JS API Client and a Python project. Let’s look at a violin plot of scores, by player, regular/playoff game, and ordered by final standing (which I conveniently already ensured was in alphabetical order, but of course you could specify any order you want, like ['BOB', 'ANN', ...]). Another strategy: ESPN uses this API to populate the site when you are poking around your league, so you can eavesdrop on these calls to get hints of what to explore. To make a clean table of all the team IDs, names, and scores for all weeks, we can do. Another rabbit hole to explore is the various other “endpoints” to the API besides scoreboard. To quantify this: take some team, plot all their games, with their score as the x-axis and their opponent’s score as the y-axis, but scaled to be relative to the league average. This is ordered by final standing. Now, plot it …. All tales as old as time. Now we can save our table as a pandas DataFrame, let’s take a look at it: Let’s get rid of the (let’s admit, completely arbitrary) home-away distinction and just get a dataframe of all scores by team. I was able to implement a lot of the stuff but not that. This means you can query a question like “what was the score of the week 1 game between ABC and XYZ” directly with a GET request and some JSON fiddling, no web “scraping” required. We can use ESPN’s API and automate this, and also get access to a much deeper well of information. Those “unlucky losses” — when you would have beat the league average team that week, but instead you got matched up against someone else who also outperformed, and lost — are the red regions. Consistency doesn’t seem to matter much, as there are high variance teams at top and bottom. Check it out. So far our API query only returns basic info about the league members. I am not getting the background to change to the image I wanted so I am wondering if espn has updated their code, making the past versions of customization code not work. Press question mark to learn the rest of the keyboard shortcuts. Kinda cool. We’ll focus on scores for now, but at the end of this post, I’ll mention some other potential here such as those playerIDs (i.e. the players on each team, by week!). If anyone has any code they are willing to share that I can use to then customize I would appreciate it. The new v3 API has two base URLs. Note: if we don’t specify the matchup period, it will default to the last week. Here’s how to grab historical projections using the new version. In this post we’ll just cover one: weekly scores with the mMatchup view. In a follow-up post, I show how to grab historical player projections and compare to reality. You should also check out my friend Dusty Turner’s excellent post about ESPN Fantasy scraping in R, and this Reddit discussion about the ESPN Fantasy API. Try it: log in to your ESPN account, and then enter the API URL, http://games.espn.com/ffl/api/v2/boxscore?leagueId=123456&seasonId=2017&matchupPeriodId=1. Visit ESPN to get up-to-the-minute sports news coverage, scores, highlights and commentary for NFL, MLB, NBA, College Football, NCAA Basketball and more. So how do we grab this data? Let’s start with Python. Mike Clay breaks down each NFL team with a key fantasy football fact to get you ahead of the curve for Week 6 and beyond. It is worth poking around this nested collection of information. created by Steven Morse with Jekyll and the Lagrange theme, "https://fantasy.espn.com/apis/v3/games/ffl/leagueHistory/", # move the team of interest to "Team1" column, Written on Using the ESPN Fantasy Football API (in Python) EDIT: ESPN changed their Fantasy API to v3 in early 2019, so lots of v2 code from this post no longer works. (To my knowledge there is nothing against ESPN’s ToS about using your own cookies for personal use within your own league.). EDIT: I think it be as simple as adding a teamId parameter, but more to follow in a later post …. Will there be any updates to the code this year? I will have to add some of this stuff to our league. If you needed to send session cookies you could of course include that as well. Has anyone seen any improvements? EDIT: ESPN changed their Fantasy API to v3 in early 2019, so lots of v2 code from this post no longer works. Manual entry of scores? Don’t worry we’re on it: Fantasy football season approacheth. share. It doesn't seem to be getting updated much but seems like a lot of customization posts I used were found here. To get richer information, we need to request specific “views” on the data. For example, using Safari’s “Timelines” Web Developer tool, or a proxy service like Charles or Fiddler. To extract the home score for this matchup, we would index deeper and call scores[1]['scoreboard']['matchups'][0]['teams'][0]['score']. Player E had the best playoff performance but had too many mediocre games in the regular season. Last year there were two posts (here and here) that gave explanations on how to customize espn league pages through use of css/java in the manager's note. Anyway let’s do this request via Python, for example: Note:. The GET request above, with parameters, is essentially equivalent to if you entered the following URL into a browser: http://games.espn.com/ffl/api/v2/scoreboard?leagueId=123456&seasonId=2017&matchupPeriodId=1. In this post I compare actual to optimal rosters along with ESPN projections. I am not getting the background to change to the image I wanted so I am wondering if espn has updated their code, making the past versions of customization code not work. To extract the first matchup of week 1, we would do scores[1]['scoreboard']['matchups'][0]. Wow pretty cool stuff. Hope this has been enjoyable, good luck this season! Expert analysis, live scoring, mock drafts, and more. Loop over weeks 1-16. It is possible to send espn_s2 cookies, swid, and other info in the GET request, but I haven’t gotten these to work. you under/overperformed, and so did your opponent, but you squeaked a win out anyway — are the blue regions. The r.json() command, in essence, translates the long, nasty JSON text into a nested data structure of Python data types. Tidyverse pipes in Pandas, Teaching R in a beginner data science class, livescoring (doesn’t seem to be working right). Boooo. Play ESPN fantasy games. Let’s also add a categorical variable Type for whether the game was regular season or playoff. This post is a crash course in what I know about it, enough to hopefully get your feet wet before the 2019 fantasy season crashes in. The API enables grabbing historical player projections, doing your own forecasts, automating player moves, in-season analysis of teams… But let’s start simple with simple game scores. Now try through a GET request and you’ll get basically an empty dict. But playoff performance absolutely does matter for the playoff teams (in this case, top 4) — in fact, Player D entered the playoffs as top seed and finished 4th. If you change violinplot to boxplot in the above code, you’ll get the image at the start of this blog. So you can skip the hassle and just use this excellent work.