-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add R script and makefile command to check urls for latest news
- Loading branch information
Showing
6 changed files
with
46 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
check: | ||
Rscript -e 'source("check_urls.R")' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
ropensci weekly emails | ||
======== | ||
|
||
check urls for a weekly news: | ||
|
||
``` | ||
make check | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
options(stringsAsFactors = FALSE) | ||
|
||
# helper functions | ||
stract <- function(str, pattern) regmatches(str, regexpr(pattern, str)) | ||
last <- function(x) x[length(x)] | ||
|
||
# get most recent news file path | ||
f <- list.files("_site", full.names = TRUE, pattern = "[0-9]{4}-[0-9]{2}-[0-9]{2}") | ||
fdates <- stract(f, "[0-9]{4}-[0-9]{2}-[0-9]{2}") | ||
path <- file.path(grep(last(sort(fdates)), f, value = TRUE), "index.html") | ||
cat("\nchecking ", path, "\n") | ||
|
||
# extract URLs | ||
|
||
require(xml2, quietly = TRUE, warn.conflicts = FALSE) | ||
html <- read_html(path) | ||
bod <- xml_find_all(html, "//body") | ||
urls <- unique(xml_attr(xml_find_all(bod, '//a[contains(@href, "http")]'), "href")) | ||
cat("found", length(urls), "URLs", "\n") | ||
|
||
# check URLs | ||
|
||
library(crul, quietly = TRUE, warn.conflicts = FALSE) | ||
conn <- crul::Async$new(urls = urls) | ||
res <- conn$get() | ||
stats <- vapply(res, "[[", numeric(1), "status_code") | ||
df <- data.frame(url = urls, code = stats) | ||
bad <- df[df$code >= 400 | df$code < 200, ] | ||
if (NROW(bad) == 0) { | ||
cat("all good :)", "\n") | ||
} else { | ||
# cat("check the following:\n", paste0(urls[1:2], collapse = "\n "), "\n") | ||
cat("check the following:", "\n") | ||
print(bad) | ||
} |