Skip to content

Instantly share code, notes, and snippets.

@Adeiko
Adeiko / db_combine.R
Created March 4, 2023 11:26
nflcom combine data
library(tidyverse)
library(httr)
library(jsonlite)
nflcom_authres <- httr::POST(
url = "https://api.nfl.com/v1/reroute",
body = list(
'grant_type' = 'client_credentials'
),
add_headers(
@Adeiko
Adeiko / leaguedata.csv
Created October 26, 2022 13:47
Median vs Simple
ld <- read.csv("Data/leaguedata.csv")
ld$index <- 1:nrow(ld)
ld2 <- ld |>
dplyr::relocate(index,.before = "LeagueID") |>
dplyr::group_by(LeagueID) |>
dplyr::mutate(
W1.rank = dplyr::case_when(rank(W1.score)>=7~0,TRUE ~ 1),
W2.rank = dplyr::case_when(rank(W2.score)>=7~0,TRUE ~ 1),
W3.rank = dplyr::case_when(rank(W3.score)>=7~0,TRUE ~ 1),
@Adeiko
Adeiko / Scrape_ADP.R
Created October 5, 2022 07:58
Scrape Google Sheet Dynasty ADP
library(tidyverse)
library(googledrive)
library(googlesheets4)
library(janitor)
library(purrr)
googledrive::drive_auth()
googlesheets4::gs4_auth(token = googledrive::drive_token())
get_adp_data <- function(year=2022){
@Adeiko
Adeiko / dkprops.R
Created September 8, 2022 22:20
Scrape DraftKings props
suppressPackageStartupMessages(library(tidyverse)) # Data "Cleaning", "manipulation", "summarization", plotting
library(jsonlite, warn.conflicts=FALSE) # To Parse Json
library(janitor) # To clean after
dk_getprops <-function(leaguetype,bettype) {
sportid <- dplyr::case_when(
magrittr::equals(leaguetype, "cfb") ~ "87637",
magrittr::equals(leaguetype, "nfl") ~ "88808",
TRUE ~ "NA"
@Adeiko
Adeiko / Merge_Combine-Rosters.R
Last active August 18, 2022 11:58
Missing draftteam/drat_number
data_rosters <- nflreadr::load_rosters(2006:2021) %>%
mutate(rosters_club = case_when(
draft_club == "ARZ" ~ "ARI",
draft_club == "BLT" ~ "BAL",
draft_club == "CLV" ~ "CLE",
draft_club == "HST" ~ "HOU",
draft_club == "OAK" ~ "LV",
draft_club == "LA" ~ "LAR",
draft_club == "SL" ~ "LAR",
draft_club == "STL" ~ "LAR",
@Adeiko
Adeiko / PFFscraper.R
Last active August 13, 2024 06:49
PFF Elite Stats Scraping
# Based on the work from Ben here: https://github.com/guga31bb/nfl_data_pipeline/tree/master/pff
# YOU NEED A PFF ELITE ACCOUNT FOR THIS
# after several downloads you may be logged out of your pff account, log in again and change to the new cookie.
suppressPackageStartupMessages(library(tidyverse)) # Data "Cleaning", "manipulation", "summarization", plotting
library(jsonlite, warn.conflicts=FALSE) # To Parse Json
library(httr) # To manage downloads
# In the browser Dev tools, check the headers of any json query in the premium stats PFF tool and put content of the header names "COOKIE" here
pff_cookie = 'XXXXXXXXX' #Change for correct cookie
while read x; do
echo -n `date +%b\ %d\ %H:%M:%S`
echo " "$x
done