Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

109 linhas
2.8KB

  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. url_nc_cf_report_get_receipts <- function() {
  11. "https://cf.ncsbe.gov/CFOrgLkup/GetReceipts"
  12. }
  13. url_nc_cf_report_get_expenditures <- function() {
  14. "https://cf.ncsbe.gov/CFOrgLkup/GetExpenditures"
  15. }
  16. match_report_type <- function(report, collapse = TRUE) {
  17. report <- toupper(report)
  18. reports <- c("RPMYSA", "RPYESA", "RPQTR1", "RPQTR2", "RPQTR3", "RPQTR4")
  19. valid <- c(
  20. reports,
  21. sub("^RP", "", reports),
  22. gsub("^RP|SA$", "", reports),
  23. sub("RPQTR", "Q", reports)
  24. )
  25. names(valid) <- rep(reports, 4)
  26. x <- names(valid)[match(report, valid)]
  27. if (any(is.na(x))) {
  28. report <- report[is.na(x)]
  29. cli::cli_abort(c("Invalid report {.val {report}}", i = "Valid: {.val {reports}}"))
  30. }
  31. if (!collapse) return(x)
  32. paste(paste0("'", x, "'"), collapse = ", ")
  33. }
  34. req_report_by_year <- function(
  35. year,
  36. report = c("RPMYSA", "RPYESA", "RPQTR1", "RPQTR2", "RPQTR3", "RPQTR4")
  37. ) {
  38. reports <- match_report_type(report)
  39. req <- request(url_nc_cf_search_doc())
  40. req <- req_url_query(req, year = year, reports = reports)
  41. req
  42. }
  43. req_report_by_year_export <- function(
  44. year,
  45. report = c("RPMYSA", "RPYESA", "RPQTR1", "RPQTR2", "RPQTR3", "RPQTR4")
  46. ) {
  47. reports <- match_report_type(report)
  48. req <- request(url_nc_cf_export_search_doc())
  49. req <- req_url_query(req, year = year, reports = reports)
  50. req
  51. }
  52. match_report_sections <- function(section) {
  53. options <- c(ALL = "all", CVR = "cover", EXP = "expenditures", REC = "receipts", EXP = "expenses")
  54. section <- arg_match(section, options)
  55. names(options)[which(section == options)]
  56. }
  57. req_report_detail <- function(report_id, section = "receipts") {
  58. section <- match_report_sections(section)
  59. req <- request(url_nc_cf_export_detail_results())
  60. # Title is needed or the page throws an error
  61. # https://cf.ncsbe.gov/CFOrgLkup/ExportDetailResults/?ReportID=197247&Type=REC&Title=JOHN
  62. req <- req_url_query(req, ReportID = report_id, Type = section, Title = "download")
  63. req
  64. }
  65. req_report_receipts <- function(report_id, page = 0, page_size = 300) {
  66. req <- request(url_nc_cf_report_get_receipts())
  67. req <- req_url_query(
  68. req,
  69. ReportID = report_id,
  70. page = page,
  71. pageSize = page_size
  72. )
  73. req
  74. }
  75. req_report_expenditures <- function(report_id, page = 0, page_size = 300) {
  76. req <- request(url_nc_cf_report_get_expenditures())
  77. req <- req_url_query(
  78. req,
  79. ReportID = report_id,
  80. page = page,
  81. pageSize = page_size,
  82. ShowIEColumns = TRUE # this doesn't appear to do anything, but it's required
  83. )
  84. req
  85. }