jthomasmock / espnscrapeR

Scrapes Or Collects NFL Data From ESPN
https://jthomasmock.github.io/espnscrapeR/
Other
51 stars 10 forks source link

get_nfl_teams() Error 403 #13

Closed IvoVillanueva closed 3 years ago

IvoVillanueva commented 3 years ago

Hi Tom, I'm trying to use the function get_nfl_teams() and not working, send me the next error

Captura de pantalla 2021-05-28 a las 21 02 59

Surely espn's api is blocked Thank u

jthomasmock commented 3 years ago

Howdy! I'm going to have to refactor to httr::GET() calls, thanks for heads up. The behavior is more consistent that way.

IvoVillanueva commented 3 years ago

Hi Tom With your permission I propose this code change so that the function works. (sorry for my English)

  get_nfl_teams <- function() {
    message("Getting NFL teams!")

    team_url <- "https://site.api.espn.com/apis/site/v2/sports/football/nfl/teams?&limit=50"
    raw_teams <- jsonlite::read_json(team_url)

      raw_teams$sports[[1]]$leagues[[1]]$teams%>%
      tibble::enframe() %>% 
      dplyr::select(-name) %>% 
      tidyr::unnest_wider(value) %>%
      tidyr::unnest_wider(team) %>% 
      dplyr::select(-links) %>%
      dplyr::as_tibble()  %>% 
      dplyr::mutate("logoDefault" = purrr::map_chr(logos, function(df) df[[1]][[1]]),
                    "logoDark" = purrr::map_chr(logos, function(df) df[[2]][[1]]),
                    "logoScoreboard" = purrr::map_chr(logos, function(df) df[[3]][[1]]),
                    "logoDarkScoreboard" = purrr::map_chr(logos, function(df) df[[4]][[1]])) %>% 
      dplyr::select(id, name:alternateColor,-shortDisplayName, logoDefault:logoDarkScoreboard) %>% 
      purrr::set_names(
        nm = c(
          "uid", "team_name", "team_nickname", "team_short_name", "full_name", "team_color",
          "alternate_color", "logodefault", "logodark", "logoscoreboard", "logodarkscoreboard"
        )) %>% 
      dplyr::mutate(
        team_color = paste0("#", team_color),
        alternate_color = paste0("#", alternate_color)
      )

  %>%
      dplyr::mutate(
        team_color = paste0("#", team_color),
        alternate_color = paste0("#", alternate_color)
      )
  }

I hope you do not mind

jthomasmock commented 3 years ago

Hi @IvoVillanueva , I've gone ahead and revamped all the functions to use httr proper so that it avoids the 503 errors.

get_nfl_teams() works again!

get_nfl_teams()
Getting NFL teams!
# A tibble: 32 x 8
   team_id team_name team_nickname team_abb team_full_name     team_color
   <chr>   <chr>     <chr>         <chr>    <chr>              <chr>     
 1 22      Cardinals Arizona       ARI      Arizona Cardinals  #A40227   
 2 1       Falcons   Atlanta       ATL      Atlanta Falcons    #000000   
 3 33      Ravens    Baltimore     BAL      Baltimore Ravens   #2B025B   
 4 2       Bills     Buffalo       BUF      Buffalo Bills      #04407F   
 5 29      Panthers  Carolina      CAR      Carolina Panthers  #2177B0   
 6 3       Bears     Chicago       CHI      Chicago Bears      #152644   
 7 4       Bengals   Cincinnati    CIN      Cincinnati Bengals #FF2700   
 8 5       Browns    Cleveland     CLE      Cleveland Browns   #4C230E   
 9 6       Cowboys   Dallas        DAL      Dallas Cowboys     #002E4D   
10 7       Broncos   Denver        DEN      Denver Broncos     #002E4D   
# … with 22 more rows, and 2 more variables: team_alt_color <chr>,
#   logo <chr>