R/upload_prediction_today.R

Defines functions upload_prediction_today

Documented in upload_prediction_today

# upload_prediction_today ------------------------------------------------------
#' Upload Prediction Today
#'
#' @param file file
#'
#' @return upload prediction today
#' @export
#'
#' @importFrom httr POST upload_file
#' @importFrom kwb.utils catAndRun
upload_prediction_today <- function(file)
{
  # Get download URL and credentials from environment variables
  url <- get_environment_variable("FTP_URL_TSB")
  user_pwd <- get_environment_variable("USER_PWD_TSB")

  user_pwd_parts <- strsplit(user_pwd, ":")[[1]]

  kwb.utils::catAndRun(
    messageText = sprintf("Uploading '%s' to the TSB server", file),
    expr = httr::POST(
      url = url,
      body = list(
        user = user_pwd_parts[1],
        pwd = user_pwd_parts[2],
        file = httr::upload_file(file)
      )
    )
  )
}
KWB-R/kwb.flusshygiene.app documentation built on July 18, 2021, 2:55 p.m.