Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

76 lines
2.0KB

  1. url_nc_cf_search_doc <- function() {
  2. "https://cf.ncsbe.gov/CFDocLkup/DocumentResult/"
  3. }
  4. url_nc_cf_export_search_doc <- function() {
  5. "https://cf.ncsbe.gov/CFDocLkup/ExportSearchResults/"
  6. }
  7. url_nc_cf_export_detail_results <- function() {
  8. "https://cf.ncsbe.gov/CFOrgLkup/ExportDetailResults/"
  9. }
  10. match_report_type <- function(report, collapse = TRUE) {
  11. report <- toupper(report)
  12. reports <- c("RPMYSA", "RPYESA", "RPQTR1", "RPQTR2", "RPQTR3", "RPQTR4")
  13. valid <- c(
  14. reports,
  15. sub("^RP", "", reports),
  16. gsub("^RP|SA$", "", reports),
  17. sub("RPQTR", "Q", reports)
  18. )
  19. names(valid) <- rep(reports, 4)
  20. x <- names(valid)[match(report, valid)]
  21. if (any(is.na(x))) {
  22. report <- report[is.na(x)]
  23. cli::cli_abort(c("Invalid report {.val {report}}", i = "Valid: {.val {reports}}"))
  24. }
  25. if (!collapse) return(x)
  26. paste(paste0("'", x, "'"), collapse = ", ")
  27. }
  28. req_report_by_year <- function(
  29. year,
  30. report = c("RPMYSA", "RPYESA", "RPQTR1", "RPQTR2", "RPQTR3", "RPQTR4")
  31. ) {
  32. reports <- match_report_type(report)
  33. req <- request(url_nc_cf_search_doc())
  34. req <- req_url_query(req, year = year, reports = reports)
  35. req
  36. }
  37. req_report_by_year_export <- function(
  38. year,
  39. report = c("RPMYSA", "RPYESA", "RPQTR1", "RPQTR2", "RPQTR3", "RPQTR4")
  40. ) {
  41. reports <- match_report_type(report)
  42. req <- request(url_nc_cf_export_search_doc())
  43. req <- req_url_query(req, year = year, reports = reports)
  44. req
  45. }
  46. match_report_sections <- function(section) {
  47. options <- c(ALL = "all", CVR = "cover", EXP = "expenditures", REC = "receipts", EXP = "expenses")
  48. section <- arg_match(section, options)
  49. names(options)[which(section == options)]
  50. }
  51. req_report_detail <- function(report_id, section = "receipts") {
  52. section <- match_report_sections(section)
  53. req <- request(url_nc_cf_export_detail_results())
  54. # Title is needed or the page throws an error
  55. # https://cf.ncsbe.gov/CFOrgLkup/ExportDetailResults/?ReportID=197247&Type=REC&Title=JOHN
  56. req <- req_url_query(req, ReportID = report_id, Type = section, Title = "download")
  57. req
  58. }