Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Imports:
scales,
utils
Suggests:
blastula,
knitr,
rmarkdown,
spelling,
Expand Down
36 changes: 35 additions & 1 deletion R/get_and_save.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
#' them again and overwrite. However you can also specify 'ignore' in which case those
#' files will be ignored. You can also investigate duplicates yourself using
#' heapsofpapers::check_for_existence().
#' @param notify a character vector of emails to notify to.
#' @param email_usr,email_pwd,email_host,email_port strings to indicate the
#' names of the environment variables containing the required parameters to send
#' an email (e.g. variables containing something such as 'mail@outlook.com',
#' 'confidentialandsecure', 'smtp.office365.com', 587)
#'
#' @return A print statement in the console about whether each of the `links` was
#' saved (if not turned off by the user), and notification that the function has
Expand Down Expand Up @@ -50,7 +55,11 @@
#'}
#' @importFrom rlang .data
get_and_save <-
function(data, links = "links", save_names = "save_names", dir = "heaps_of", bucket = NULL, delay = 5, print_every = 1, dupe_strategy = "overwrite"){
function(data, links = "links", save_names = "save_names", dir = "heaps_of",
bucket = NULL, delay = 5, print_every = 1, dupe_strategy = "overwrite",
notify = NULL, email_usr = "HEAPS_SMTP_USER", email_pwd = "HEAPS_SMTP_PASSWORD",
email_host = "HEAPS_SMTP_HOST",
email_port = "HEAPS_SMTP_PORT"){

if (isFALSE(curl::has_internet())) {
stop("The function get_and_save() needs the internet, but isn't able to find a connection right now.")
Expand Down Expand Up @@ -160,5 +169,30 @@ get_and_save <-
}
}

if (!is.null(notify)) {
if (isFALSE(requireNamespace("blastula", quietly = TRUE))) {
stop("heapsofpapers requires blastula to send emails.")
}

email <- blastula::compose_email(
body = blastula::md("Hello. The download was completed. Have a good day!"),
footer = blastula::md("This is an automated email created with the heapsofpapers R package.")
)

email %>%
blastula::smtp_send(
to = notify,
from = Sys.getenv(email_usr, unset = NA),
subject = "heapsofpapers: The download was completed",
credentials = blastula::creds_envvar(
user = Sys.getenv(email_usr, unset = NA),
pass_envvar = email_pwd,
host = Sys.getenv(email_host, unset = NA),
port = Sys.getenv(email_port, unset = NA),
use_ssl = TRUE
)
)
}

}

14 changes: 13 additions & 1 deletion man/get_and_save.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.