Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
howardbaik committed Oct 2, 2023
1 parent 7eb2a56 commit 3288bfd
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 27 deletions.
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export(extract_quiz)
export(get_bookdown_spec)
export(get_chapters)
export(get_gs_pptx)
export(get_gs_slide_pptx)
export(get_image_from_slide)
export(get_image_link_from_slide)
export(get_object_id_notes)
Expand Down
1 change: 0 additions & 1 deletion R/gs_png.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ gs_png_download <- function(url, output_dir = ".", overwrite = TRUE) {
include_slide <- function(url,
output_dir = knitr::opts_chunk$get("fig.path"),
overwrite = TRUE, ...) {
alt_text <<- # extract alt text from slide
outfile <- gs_png_download(url, output_dir, overwrite = overwrite)
knitr::include_graphics(outfile, ...)
}
53 changes: 50 additions & 3 deletions R/notes_to_fig_alt.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
#' @export
get_gs_pptx <- function(id) {
id <- as.character(id)
pres_id <- get_presentation_id(id)
url <- export_url(id = pres_id)
presentation_id <- get_presentation_id(id)
url <- export_url(presentation_id = presentation_id)

pptx_file <- file.path(paste0(pres_id, ".pptx"))
pptx_file <- file.path(paste0(presentation_id, ".pptx"))

# Only download it if it isn't yet present
if (!file.exists(pptx_file)) {
Expand Down Expand Up @@ -48,6 +48,53 @@ get_gs_pptx <- function(id) {
pptx_file
}


# WIP: get_gs_slide_pptx()
get_gs_slide_pptx <- function(link) {
link <- as.character(link)
presentation_id <- get_presentation_id(link)
slide_id <- get_slide_id(link)
url <- export_url(presentation_id = presentation_id, slide_id = slide_id)

pptx_file <- file.path(paste0(presentation_id, slide_id, ".pptx"))

# Only download it if it isn't yet present
if (!file.exists(pptx_file)) {
result <- httr::GET(url, httr::write_disk(pptx_file))
warn_them <- FALSE
fr_header <- result$headers$`x-frame-options`
if (!is.null(fr_header)) {
if (all(fr_header == "DENY")) {
warn_them <- TRUE
}
}
if (httr::status_code(result) >= 300) {
warn_them <- TRUE
}
# don't write something if not really a pptx
ctype <- result$headers$`content-type`
if (httr::status_code(result) >= 400 &&
!is.null(ctype) && grepl("html", ctype)) {
file.remove(pptx_file)
}
if (grepl("ServiceLogin", result$url)) {
warn_them <- TRUE
}
if (warn_them) {
warning(
paste0(
"This presentation may not be available, ",
"did you turn link sharing on?"
)
)
}
}
pptx_file
}




export_url <- function(presentation_id, slide_id = NULL, type = "pptx") {
url = paste0(
"https://docs.google.com/presentation/d/",
Expand Down
22 changes: 0 additions & 22 deletions man/get_gs_slide_pptx.Rd

This file was deleted.

0 comments on commit 3288bfd

Please sign in to comment.