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.

rrtypes.R 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. ## code to prepare `rrtypes` dataset goes here
  2. library(tidyverse)
  3. library(xml2)
  4. xdf <- read_csv("https://www.iana.org/assignments/dns-parameters/dns-parameters-2.csv")
  5. dns_classes <- janitor::clean_names(xdf)
  6. usethis::use_data(dns_classes, overwrite = TRUE)
  7. xdf <- read_csv("https://www.iana.org/assignments/dns-parameters/dns-parameters-4.csv")
  8. rrtypes <- janitor::clean_names(xdf)
  9. usethis::use_data(rrtypes, overwrite = TRUE)
  10. xdf <- read_csv("https://www.iana.org/assignments/dns-parameters/dns-parameters-5.csv")
  11. dns_opcodes <- janitor::clean_names(xdf)
  12. usethis::use_data(dns_opcodes, overwrite = TRUE)
  13. xdf <- read_csv("https://www.iana.org/assignments/dns-parameters/dns-parameters-6.csv")
  14. dns_rcodes <- janitor::clean_names(xdf)
  15. usethis::use_data(dns_rcodes, overwrite = TRUE)
  16. xdf <- read_csv("https://www.iana.org/assignments/dns-parameters/dns-parameters-11.csv")
  17. edns0_option_codes <- janitor::clean_names(xdf)
  18. usethis::use_data(edns0_option_codes, overwrite = TRUE)
  19. xdf <- read_csv("https://www.iana.org/assignments/dns-parameters/underscored-globally-scoped-dns-node-names.csv")
  20. dns_glob_names <- janitor::clean_names(xdf)
  21. usethis::use_data(dns_glob_names, overwrite = TRUE)
  22. # https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml
  23. doc <- read_xml("https://www.iana.org/assignments/dns-parameters/dns-parameters.xml")
  24. doc <- xml_ns_strip(doc)
  25. fil <- here::here("R/datasets.R")
  26. upd <- as.character(Sys.time())
  27. c(
  28. "dns_classes" = "dns-parameters-2",
  29. "rrtypes" = "dns-parameters-4",
  30. "dns_opcodes" = "dns-parameters-5",
  31. "dns_rcodes" = "dns-parameters-6",
  32. "edns0_option_codes" = "dns-parameters-11",
  33. "dns_glob_names" = "underscored-globally-scoped-dns-node-names"
  34. ) -> ids
  35. cat(
  36. "# This file is autogenerated. Do not edit by hand.\n",
  37. "# Last refresh: ", upd, "\n\n", sep = "",
  38. file = fil
  39. )
  40. for (i in seq_along(ids)) {
  41. dat <- names(ids)[i]
  42. id <- unname(ids)[i]
  43. id <- glue::glue(".//registry[@id = '{id}']")
  44. node <- xml_find_first(doc, id)
  45. note <- ""
  46. if (!is.na(xml_text(xml_find_first(node, "note"))[[1]])) {
  47. note <- sprintf("#' @note %s\n", gsub("\n", "", paste0(xml_text(xml_find_first(node, "note")), collapse = " ")))
  48. }
  49. cat(
  50. "#' @md\n",
  51. "#' @title ", xml_text(xml_find_first(node, "title")), " (dataset)\n",
  52. "#' @description ", xml_text(xml_find_first(node, "title")), "\n",
  53. "#' @format data frame with columns: ", paste0(sprintf("`%s`", colnames(get(names(ids)[i]))), collapse = ", "), "\n",
  54. "#' @docType data\n",
  55. "#' @keywords datasets\n",
  56. "#' @name ", dat, "\n",
  57. "#' @references <https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#", unname(ids)[i], ">\n",
  58. "#' @references <https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml>\n",
  59. "#' @references ", paste0(xml_attr(xml_find_all(node, "xref"), "data"), collapse = ", "), "\n",
  60. note,
  61. "#' @note Last updated ", upd, "\n",
  62. "#' @usage data('", dat, "')\n",
  63. "NULL\n\n",
  64. sep = "", file = fil, append = TRUE
  65. )
  66. }