Skip to content

Instantly share code, notes, and snippets.

@solmos
Last active March 12, 2019 12:32
Show Gist options
  • Save solmos/7aab64ce561461bd6d2f1c68432c303a to your computer and use it in GitHub Desktop.
Save solmos/7aab64ce561461bd6d2f1c68432c303a to your computer and use it in GitHub Desktop.
library(httr)
library(jsonlite)
library(rfeb)
# Función para obtener los resultados de los partidos que aparecen en Baloncesto en Vivo en este momento
# competition puede ser: "Liga LEB Oro", "Liga Dia", "Liga LEB Plata", "L.F.-2", "EBA"
get_round_results <- function(competition = "Liga LEB Oro") {
api <- GET("http://baloncestoenvivo.feb.es/api/OverView/")
data_json <- content(api, as = "text", encoding = "UTF-8")
data <- fromJSON(data_json)
competitions <- data$OVERVIEW$COMPETITIONS$name
i <- which(competition == competitions)
round_data <- data$OVERVIEW$COMPETITIONS$GAMES[[i]]
round_data <- round_data[c("ID", "TeamA", "ScoreA", "TeamB", "ScoreB",
"Status", "StartTime", "GameTime", "Quarter",
"Stage", "Time", "Place", "TeamAID", "TeamBID",
"LogoA", "LogoB")]
# if(Time != "FINAL") cat("Quedan partidos por jugar/terminar")
round_data
}
leboro <- get_round_results()
leboro$ID
# Two sets of overlaping games
game_set1 <- leboro$ID[1:4]
game_set2 <- leboro$ID[3:length(leboro$ID)]
shots1 <- extract_shots(game_set1)
shots2 <- extract_shots(game_set2)
shots <- rbind(shots1, shots2)
unique_shots <- unique.data.frame(shots)
# or dplyr::distinct(shots)
correct_shots <- extract_shots(leboro$ID)
nrow(correct_shots) == nrow(unique_shots)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment