Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webshot -> webshot2 #37

Merged
merged 5 commits into from
Jun 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions scripts/make_screenshots.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -55,15 +53,22 @@ 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 <- 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
webshot::webshot(url, file_name)

# Get rid of special characters because leanpub no like
file_name <- gsub(":|?|!|\\'", "", file_name)
message(paste("Screenshot saved:", file_name))

# Take the screenshot
webshot2::webshot(url, file = file_name)

return(file_name)

})

# Save file of chapter urls and file_names
Expand Down
Loading