From cfd8dedddacfdbf196fa1e25a12f05dc72c97729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Briatte?= Date: Thu, 27 Apr 2023 00:04:41 +0200 Subject: [PATCH] Update check.r --- check.r | 60 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/check.r b/check.r index 977fb2b..dc2f472 100755 --- a/check.r +++ b/check.r @@ -13,46 +13,46 @@ library(stringr) f <- "check.log" if (!file.exists(f)) { - + u <- str_c( "https://raw.githubusercontent.com/", "briatte/awesome-network-analysis/", "master/README.md" ) - + cat("Source:", u, "\n") - + u <- GET(u) %>% content("text") %>% str_split("\\n") %>% # so as to find [foo]: bar links - unlist - + unlist() + # total number of links (made to match web.archive.org links only once) t <- sum(str_count(u, "(?% lapply(str_replace_all, "^\\(|\\)$", "") %>% - unlist, + unlist(), # [foo]: bar - str_extract_all(u, "^\\[(.*)\\]: (.*)") %>% - unlist %>% + str_extract_all(u, "^\\[(.*)\\]: (.*)") %>% + unlist() %>% str_replace("^\\[(.*)\\]: (.*)", "\\2") ) - + stopifnot(length(l) == t) - + } else { - + cat("Source:", f, "\n") - + l <- str_subset(stringi::stri_read_lines(f), "^http") - + cat(length(l), "URLs, ") - + } l <- str_squish(sort(unique(l))) @@ -67,37 +67,37 @@ cat(as.character(Sys.time()), ": checking", length(l), "URLs\n\n") sink() for (i in l) { - + x <- try(status_code(GET(i)), silent = TRUE) - + if (!"try-error" %in% class(x) && x != 200) { - + cat("X") - + sink(f, append = TRUE) cat(i, "\nStatus code:", x, "\n\n") sink() - + } else if ("try-error" %in% class(x)) { - + cat("?") - + sink(f, append = TRUE) cat(i, "\nFailed to access\n\n") sink() - + } else { - + cat(".") - + } - + if (!which(l == i) %% 50) { - + cat("", length(l) - which(l == i), "left\n") - + } - + } sink(f, append = TRUE)