Skip to content

Instantly share code, notes, and snippets.

@jeffgswanson
Last active August 13, 2023 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffgswanson/703bb9eb1698518d1dd9aec43e91fefd to your computer and use it in GitHub Desktop.
Save jeffgswanson/703bb9eb1698518d1dd9aec43e91fefd to your computer and use it in GitHub Desktop.
Class B NE Basketball Rankings
# Activate these packages
library(shiny)
library(DT)
library(shinythemes)
library(rvest)
library(expss)
library(dplyr)
library(tidyr)
library(stringr)
library(sqldf)
library(scales)
# List of schools and class (2023): https://nsaa-static.s3.amazonaws.com/textfile/bask/bbbclass.pdf
# Manually create Class B names and enrollment dataframe
School <-
c(
'South Sioux City',
'Hastings',
'Ralston',
'Scottsbluff',
'Bennington',
'Lexington',
'Elkhorn North',
'Norris',
'Waverly',
'Elkhorn',
'Omaha Skutt Catholic',
'Crete',
'Blair',
'Northwest',
'Lincoln Northwest',
'Beatrice',
'Gering',
'Schuyler',
'Seward',
'Mount Michael Benedictine',
'Nebraksa City',
'Plattsmouth',
'York',
'Plattview',
'Omaha Gross Catholic',
'Omaha Roncalli Catholic',
'Alliance',
'McCook'
)
Enrollment <-
c(
'438',
'438',
'395',
'382',
'367',
'367',
'356',
'291',
'289',
'286',
'281',
'277',
'263',
'254',
'250',
'250',
'239',
'237',
'201',
'191',
'186',
'184',
'170',
'159',
'157',
'157',
'149',
'145'
)
classB <- data.frame(School, Enrollment)
# create game scores table -- I added game dates manually
maxprep_baseURL <-
"https://www.maxpreps.com/ne/basketball/22-23/division/class-b/scores/?date="
maxprep_paramURL <-
"&statedivisionid=33b090f9-1638-4122-b840-f566f190da70"
game_dates <- c(
"12/1/2022",
"12/2/2022",
"12/3/2022",
"12/6/2022",
"12/8/2022",
"12/9/2022",
"12/10/2022",
"12/13/2022",
"12/15/2022",
"12/16/2022",
"12/17/2022",
"12/20/2022",
"12/28/2022",
"12/29/2022",
"12/30/2022",
"1/2/2023",
"1/3/2023",
"1/5/2023",
"1/6/2023",
"1/7/2023",
"1/9/2023",
"1/10/2023",
"1/12/2023",
"1/13/2023",
"1/14/2023",
"1/16/2023",
"1/17/2023",
"1/18/2023",
"1/19/2023",
"1/20/2023",
"1/21/2023",
"1/23/2023",
"1/24/2023",
"1/26/2023",
"1/27/2023",
"1/28/2023",
"1/31/2023",
"2/2/2023",
"2/3/2023",
"2/4/2023",
"2/6/2023",
"2/7/2023",
"2/9/2023",
"2/10/2023",
"2/11/2023",
"2/13/2023",
"2/14/2023",
"2/16/2023",
"2/17/2023",
"2/18/2023",
"2/22/2023",
"2/23/2023",
"2/27/2023",
"2/8/2023",
"2/9/2023",
"2/10/2023",
"2/11/2023"
)
maxprep_page_list <-
as.list(paste0(maxprep_baseURL, game_dates, maxprep_paramURL))
maxprep_html <- lapply(maxprep_page_list, FUN=function(URLLink){
read_html(URLLink) %>% html_nodes("[data-contest-state='boxscore']") %>% html_text(trim = FALSE)
})
# Unlist
scores <-
unlist(maxprep_html)
scores <-
gsub("Final","", scores)
scores <-
data.frame(scores)
colnames(scores) <-
c("V1")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment