Skip to content

Instantly share code, notes, and snippets.

@nikdata
Created February 1, 2021 01:56
Show Gist options
  • Select an option

  • Save nikdata/15e3deac984dd3194566aee0daa85f37 to your computer and use it in GitHub Desktop.

Select an option

Save nikdata/15e3deac984dd3194566aee0daa85f37 to your computer and use it in GitHub Desktop.
Get latest Wall Street Journal (WSJ) crossword
fetch_xwd <- function(date) {
if(missing(date)) {
cur_date <- Sys.Date()
} else {
cur_date <- date
}
dayofweek <- as.character(lubridate::wday(cur_date, label = TRUE))
# wsj doesn't have a crossword on their site for sunday, so we get the saturday one
if(dayofweek == 'Sun') {
cur_date = cur_date - 1
}
file_date <- as.character(format(cur_date, '%m%d%Y'))
base_url <- "https://s.wsj.net/public/resources/documents/XWD"
file_name <- paste0(file_date,'.pdf')
full_url <- paste0(base_url,file_name)
dest_filename <- paste0(file_date,'_wsjcw.pdf')
if(RCurl::url.exists(full_url)) {
download.file(url = full_url, destfile = paste0(getwd(),'/Desktop/', dest_filename), quiet=TRUE)
} else {
message("Bad URL; Please check the URL and try again")
message(paste0('URL used: ',full_url))
return(invisible(NULL))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment