Skip to content

Instantly share code, notes, and snippets.

View mrcaseb's full-sized avatar

mrcaseb

  • Munich, Germany
  • 05:10 (UTC +02:00)
  • X @mrcaseb
View GitHub Profile
@mrcaseb
mrcaseb / function_get_espn_wp_college.R
Created April 15, 2020 18:47
Function for scraping win probability data from the ESPN API. Outputs game_id, play_id and home_wp and should therefore be joinable to cfbscrapR data.
library(dplyr)
get_espn_wp_college <- function(espn_game_id) {
espn_wp <- data.frame()
tryCatch(
expr = {
espn_wp <-
httr::GET(url = glue::glue("http://site.api.espn.com/apis/site/v2/sports/football/college-football/summary?event={espn_game_id}")) %>%
httr::content(as = "text", encoding = "UTF-8") %>%
jsonlite::fromJSON(flatten = TRUE) %>%
purrr::pluck("winprobability") %>%