From 407dc3b38f47f2ea9ee726433bba14f9b4fd051f Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Mon, 24 Jun 2024 15:49:17 -0400 Subject: [PATCH 1/4] Fix webshot -> webshot2 --- scripts/make_screenshots.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/make_screenshots.R b/scripts/make_screenshots.R index c57a182..f239a78 100644 --- a/scripts/make_screenshots.R +++ b/scripts/make_screenshots.R @@ -9,8 +9,6 @@ if (!('optparse' %in% installed.packages())) { # install.packages("optparse", repos = "http://cran.us.r-project.org") } -webshot::install_phantomjs() - library(optparse) library(magrittr) @@ -59,9 +57,11 @@ chapt_df <- ottrpal::get_chapters(base_url = file.path(base_url, "no_toc/")) 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 - webshot::webshot(url, file_name) + b$Page$navigate(url, file_name) file_name <- gsub(":|?|!|\\'", "", file_name) + b$screenshot(file_name) message(paste("Screenshot saved:", file_name)) return(file_name) }) From c4beb5cb7196be9ce02688999b24ed36138f2ad1 Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Mon, 24 Jun 2024 16:14:29 -0400 Subject: [PATCH 2/4] Changing to webshot2 --- scripts/make_screenshots.R | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/scripts/make_screenshots.R b/scripts/make_screenshots.R index f239a78..4437360 100644 --- a/scripts/make_screenshots.R +++ b/scripts/make_screenshots.R @@ -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 From 95bf2bcb7718f3d3e31b0a40c9c819a0b8d35582 Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Mon, 24 Jun 2024 16:23:12 -0400 Subject: [PATCH 3/4] Update! --- scripts/make_screenshots.R | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/scripts/make_screenshots.R b/scripts/make_screenshots.R index 4437360..1f38e98 100644 --- a/scripts/make_screenshots.R +++ b/scripts/make_screenshots.R @@ -61,20 +61,11 @@ chapt_df <- get_chapters(html_page = file.path(base_url, "no_toc/")) file_names <- lapply(chapt_df$url, function(url) { file_name <- gsub(".html", ".png", file.path(output_folder, basename(url))) - # 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) - + # Take the screenshot - chrome_session$screenshot(file.path(file_name)) - - message(paste("Screenshot saved:", file_name)) - - # Close it - chrome_session$close() + webshot2::webshot(url) return(file_name) From 57c4f5a7e14ee69c103be056798569d1fd334379 Mon Sep 17 00:00:00 2001 From: Candace Savonen Date: Wed, 26 Jun 2024 08:44:56 -0400 Subject: [PATCH 4/4] Fix filepath --- scripts/make_screenshots.R | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/make_screenshots.R b/scripts/make_screenshots.R index 1f38e98..1c6b9ad 100644 --- a/scripts/make_screenshots.R +++ b/scripts/make_screenshots.R @@ -54,21 +54,21 @@ if (is.null(opt$base_url)) { } # Collect all the chapter pages for the url given -chapt_df <- get_chapters(html_page = file.path(base_url, "no_toc/")) +chapt_df <- ottrpal::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))) - + # Get rid of special characters because leanpub no like file_name <- gsub(":|?|!|\\'", "", file_name) # Take the screenshot - webshot2::webshot(url) - + webshot2::webshot(url, file = file_name) + return(file_name) - + }) # Save file of chapter urls and file_names