mirror of
https://github.com/briatte/awesome-network-analysis.git
synced 2024-10-01 01:06:13 -04:00
make check.r cumulative
if check.log is present, checks only the URLs in that file
This commit is contained in:
parent
a3155cdfc7
commit
db6f343a9a
47
check.r
47
check.r
@ -1,24 +1,30 @@
|
|||||||
library(httr)
|
library(httr)
|
||||||
library(stringr)
|
library(stringr)
|
||||||
|
|
||||||
u <- str_c(
|
f <- "check.log"
|
||||||
|
|
||||||
|
if (!file.exists(f)) {
|
||||||
|
|
||||||
|
u <- str_c(
|
||||||
"https://raw.githubusercontent.com/",
|
"https://raw.githubusercontent.com/",
|
||||||
"briatte/awesome-network-analysis/",
|
"briatte/awesome-network-analysis/",
|
||||||
"master/README.md"
|
"master/README.md"
|
||||||
)
|
)
|
||||||
|
|
||||||
u <- GET(u) %>%
|
cat("Source:", u, "\n")
|
||||||
|
|
||||||
|
u <- GET(u) %>%
|
||||||
content("text") %>%
|
content("text") %>%
|
||||||
str_split("\\n") %>% # so as to find [foo]: bar links
|
str_split("\\n") %>% # so as to find [foo]: bar links
|
||||||
unlist
|
unlist
|
||||||
|
|
||||||
# total number of links
|
# total number of links
|
||||||
t <- str_count(u, "http") %>%
|
t <- str_count(u, "http") %>%
|
||||||
sum
|
sum
|
||||||
|
|
||||||
cat(t, "URLs, ")
|
cat(t, "URLs, ")
|
||||||
|
|
||||||
l <- c(
|
l <- c(
|
||||||
# [foo](bar)
|
# [foo](bar)
|
||||||
str_extract_all(u, "\\(http(.*?)\\)") %>%
|
str_extract_all(u, "\\(http(.*?)\\)") %>%
|
||||||
lapply(str_replace_all, "^\\(|\\)$", "") %>%
|
lapply(str_replace_all, "^\\(|\\)$", "") %>%
|
||||||
@ -27,16 +33,27 @@ l <- c(
|
|||||||
str_extract_all(u, "^\\[(.*)\\]: (.*)") %>%
|
str_extract_all(u, "^\\[(.*)\\]: (.*)") %>%
|
||||||
unlist %>%
|
unlist %>%
|
||||||
str_replace("^\\[(.*)\\]: (.*)", "\\2")
|
str_replace("^\\[(.*)\\]: (.*)", "\\2")
|
||||||
)
|
)
|
||||||
|
|
||||||
stopifnot(length(l) == t)
|
stopifnot(length(l) == t)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
cat("Source:", f, "\n")
|
||||||
|
|
||||||
|
l <- readLines(f) %>%
|
||||||
|
str_subset("^http")
|
||||||
|
|
||||||
|
cat(length(l), "URLs, ")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
l <- unique(l) %>%
|
l <- unique(l) %>%
|
||||||
sort
|
sort
|
||||||
|
|
||||||
cat(length(l), "unique\n")
|
cat(length(l), "unique\n")
|
||||||
|
|
||||||
sink("check.log", append = FALSE)
|
sink(f, append = FALSE)
|
||||||
cat(as.character(Sys.time()), ": checking", length(l), "URLs\n\n")
|
cat(as.character(Sys.time()), ": checking", length(l), "URLs\n\n")
|
||||||
sink()
|
sink()
|
||||||
|
|
||||||
@ -50,7 +67,7 @@ for (i in l) {
|
|||||||
|
|
||||||
cat("X")
|
cat("X")
|
||||||
|
|
||||||
sink("check.log", append = TRUE)
|
sink(f, append = TRUE)
|
||||||
cat(i, "\nStatus code:", x, "\n\n")
|
cat(i, "\nStatus code:", x, "\n\n")
|
||||||
sink()
|
sink()
|
||||||
|
|
||||||
@ -58,9 +75,10 @@ for (i in l) {
|
|||||||
|
|
||||||
cat("?")
|
cat("?")
|
||||||
|
|
||||||
sink("check.log", append = TRUE)
|
sink(f, append = TRUE)
|
||||||
cat(i, "\nFailed to access\n\n")
|
cat(i, "\nFailed to access\n\n")
|
||||||
sink()
|
sink()
|
||||||
|
Sys.sleep(5)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@ -73,11 +91,10 @@ for (i in l) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sink("check.log", append = TRUE)
|
sink(f, append = TRUE)
|
||||||
cat(as.character(Sys.time()), ": done.\n")
|
cat(as.character(Sys.time()), ": done.\n")
|
||||||
sink()
|
sink()
|
||||||
|
|
||||||
cat("Found", str_count(readLines("check.log"), "^http:") %>%
|
cat("Found", str_count(readLines(f), "^http") %>%
|
||||||
sum,
|
sum,
|
||||||
"problems.\n")
|
"problems.\n")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user