Tools to work with the Google DNS over HTTPS API in R https://cinc.rud.is/web/packages/gdns/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
3.0 KiB

## code to prepare `rrtypes` dataset goes here
library(tidyverse)
library(xml2)
xdf <- read_csv("https://www.iana.org/assignments/dns-parameters/dns-parameters-2.csv")
dns_classes <- janitor::clean_names(xdf)
usethis::use_data(dns_classes, overwrite = TRUE)
xdf <- read_csv("https://www.iana.org/assignments/dns-parameters/dns-parameters-4.csv")
rrtypes <- janitor::clean_names(xdf)
usethis::use_data(rrtypes, overwrite = TRUE)
xdf <- read_csv("https://www.iana.org/assignments/dns-parameters/dns-parameters-5.csv")
dns_opcodes <- janitor::clean_names(xdf)
usethis::use_data(dns_opcodes, overwrite = TRUE)
xdf <- read_csv("https://www.iana.org/assignments/dns-parameters/dns-parameters-6.csv")
dns_rcodes <- janitor::clean_names(xdf)
usethis::use_data(dns_rcodes, overwrite = TRUE)
xdf <- read_csv("https://www.iana.org/assignments/dns-parameters/dns-parameters-11.csv")
edns0_option_codes <- janitor::clean_names(xdf)
usethis::use_data(edns0_option_codes, overwrite = TRUE)
xdf <- read_csv("https://www.iana.org/assignments/dns-parameters/underscored-globally-scoped-dns-node-names.csv")
dns_glob_names <- janitor::clean_names(xdf)
usethis::use_data(dns_glob_names, overwrite = TRUE)
# https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml
doc <- read_xml("https://www.iana.org/assignments/dns-parameters/dns-parameters.xml")
doc <- xml_ns_strip(doc)
fil <- here::here("R/datasets.R")
upd <- as.character(Sys.time())
c(
"dns_classes" = "dns-parameters-2",
"rrtypes" = "dns-parameters-4",
"dns_opcodes" = "dns-parameters-5",
"dns_rcodes" = "dns-parameters-6",
"edns0_option_codes" = "dns-parameters-11",
"dns_glob_names" = "underscored-globally-scoped-dns-node-names"
) -> ids
cat(
"# This file is autogenerated. Do not edit by hand.\n",
"# Last refresh: ", upd, "\n\n", sep = "",
file = fil
)
for (i in seq_along(ids)) {
dat <- names(ids)[i]
id <- unname(ids)[i]
id <- glue::glue(".//registry[@id = '{id}']")
node <- xml_find_first(doc, id)
note <- ""
if (!is.na(xml_text(xml_find_first(node, "note"))[[1]])) {
note <- sprintf("#' @note %s\n", gsub("\n", "", paste0(xml_text(xml_find_first(node, "note")), collapse = " ")))
}
cat(
"#' @md\n",
"#' @title ", xml_text(xml_find_first(node, "title")), " (dataset)\n",
"#' @description ", xml_text(xml_find_first(node, "title")), "\n",
"#' @format data frame with columns: ", paste0(sprintf("`%s`", colnames(get(names(ids)[i]))), collapse = ", "), "\n",
"#' @docType data\n",
"#' @keywords datasets\n",
"#' @name ", dat, "\n",
"#' @references <https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#", unname(ids)[i], ">\n",
"#' @references <https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml>\n",
"#' @references ", paste0(xml_attr(xml_find_all(node, "xref"), "data"), collapse = ", "), "\n",
note,
"#' @note Last updated ", upd, "\n",
"#' @usage data('", dat, "')\n",
"NULL\n\n",
sep = "", file = fil, append = TRUE
)
}