Skip to content

Commit

Permalink
Implement automatic editing v1. (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonthegeek authored May 18, 2023
1 parent 373aad6 commit 5325704
Show file tree
Hide file tree
Showing 6 changed files with 443 additions and 313 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: bookclubcron
Title: Automated Tasks for R4DS Book Clubs
Version: 0.0.0.9000
Version: 0.0.1
Authors@R:
person("Jon", "Harmon", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-4781-4346"))
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ export(process_zoom)
export(r4ds_slack_channels)
export(r4ds_youtube_playlists)
export(reset_the)
importFrom(rlang,"%||%")
importFrom(rlang,.data)
importFrom(rlang,.env)
1 change: 1 addition & 0 deletions R/bookclubcron-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"_PACKAGE"

## usethis namespace: start
#' @importFrom rlang %||%
#' @importFrom rlang .data
#' @importFrom rlang .env
## usethis namespace: end
Expand Down
6 changes: 5 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
log_now <- function() {
now <- format(
Sys.time(),
format = "%F %T"
)
return(
glue::glue("{lubridate::now()} |")
glue::glue("{now} |")
)
}
36 changes: 16 additions & 20 deletions R/youtube.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ r4ds_youtube_playlists <- function(n = 50L, refresh = FALSE) {
#' @return I'm not sure yet.
#' @export
process_youtube <- function() {
# TODO: Consider renaming this to something like "process_uploaded_videos".

working_video_path <- fs::path(
rappdirs::user_cache_dir("bookclubcron"),
"youtube_video_status",
Expand Down Expand Up @@ -177,22 +175,26 @@ process_youtube <- function() {

if (working_yt_videos$status[[this_row]] == "uploaded") {
msg <- "{log_now()} {channel_name} is {.href [editable]({vid_url})}!"
cli::cli_inform(msg)
cli::cli_alert_info(msg)
return(status_tbl)
}
if (working_yt_videos$status[[this_row]] == "processed") {
previous_duration <- working_yt_videos$uploaded_duration[[this_row]]
if (status_tbl$uploaded_duration < previous_duration) {
cli::cli_inform("{log_now()} {channel_name} is {.emph DONE!}")

# Make it public.
youtubeR::yt_videos_update(
video_id = this_video$id,
status = youtubeR::yt_schema_video_status(
privacy_status = "public"
if (
status_tbl$uploaded_duration < previous_duration ||
this_video$status$privacyStatus == "public"
) {
cli::cli_alert_info("{log_now()} {channel_name} is {.emph DONE!}")

if (this_video$status$privacyStatus != "public") {
# Make it public.
youtubeR::yt_videos_update(
video_id = this_video$id,
status = youtubeR::yt_schema_video_status(
privacy_status = "public"
)
)
)

}
slack_channels <- r4ds_slack_channels()

slack_msg <- glue::glue(
Expand All @@ -208,7 +210,7 @@ process_youtube <- function() {
text = slack_msg
)
} else {
cli::cli_warn(c(
cli::cli_alert_warning(c(
"!" = "{log_now()} Cannot find channel {channel_name}.",
"!" = "Did you change it?",
"i" = slack_msg
Expand All @@ -220,16 +222,10 @@ process_youtube <- function() {
status_tbl$status <- "ready"
return(status_tbl)
}
msg <- paste(
"{log_now()} {channel_name} is {.href [editable]({vid_url})},",
"or the edit is processing."
)
cli::cli_inform(msg)
}
# No change so no need to return anything.
return(NULL)
}
cli::cli_inform("{log_now()} {channel_name} is {.emph not yet processed.}")
return(NULL)
}
) |>
Expand Down
Loading

0 comments on commit 5325704

Please sign in to comment.