Skip to content

Commit

Permalink
Changing to webshot2
Browse files Browse the repository at this point in the history
  • Loading branch information
cansavvy committed Jun 24, 2024
1 parent 28fae1b commit c4beb5c
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions scripts/make_screenshots.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,31 @@ if (is.null(opt$base_url)) {
base_url <- gsub("/$", "", base_url)
}

chapt_df <- ottrpal::get_chapters(base_url = file.path(base_url, "no_toc/"))
# Collect all the chapter pages for the url given
chapt_df <- get_chapters(html_page = file.path(base_url, "no_toc/"))


# Now take screenshots for each
file_names <- lapply(chapt_df$url, function(url) {
file_name <- gsub(".html", ".png", file.path(output_folder, basename(url)))
b <- chromote::ChromoteSession$new()
# Get rid of special characters
b$Page$navigate(url, file_name)

# Open a session
chrome_session <- chromote::ChromoteSession$new()

# Get rid of special characters because leanpub no like
suppressWarnings(chrome_session$Page$navigate(url, "_", file_name))
file_name <- gsub(":|?|!|\\'", "", file_name)
b$screenshot(file_name)

# Take the screenshot
chrome_session$screenshot(file.path(file_name))

message(paste("Screenshot saved:", file_name))

# Close it
chrome_session$close()

return(file_name)

})

# Save file of chapter urls and file_names
Expand Down

0 comments on commit c4beb5c

Please sign in to comment.