Skip to content

Commit

Permalink
alt_text
Browse files Browse the repository at this point in the history
  • Loading branch information
howardbaik committed Oct 2, 2023
1 parent 3288bfd commit 9226487
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 47 deletions.
8 changes: 8 additions & 0 deletions R/gs_png.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ gs_png_download <- function(url, output_dir = ".", overwrite = TRUE) {
include_slide <- function(url,
output_dir = knitr::opts_chunk$get("fig.path"),
overwrite = TRUE, ...) {
# Get speaker notes for ALL slides
all_speaker_notes <- get_object_id_notes(url)

# Get slide speaker notes
slide_id <- get_slide_id(url)
slide_speaker_notes <- all_speaker_notes[all_speaker_notes$id == slide_id, "notes"]

alt_text <<- slide_speaker_notes
outfile <- gs_png_download(url, output_dir, overwrite = overwrite)
knitr::include_graphics(outfile, ...)
}
47 changes: 0 additions & 47 deletions R/notes_to_fig_alt.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,53 +48,6 @@ 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

0 comments on commit 9226487

Please sign in to comment.