dev/sbir_award_dl.R

devtools::load_all(".")
library(tidyverse)
library(asbmisc)
library(rvest)
setwd("~")
df_awards <-
  "Desktop/r_packages/govtrackRdata/data/sibr_awards.rda" %>%
  read_rda_file()

library(furrr)
library(future)

setwd("Desktop/data/sbir/awards/")
.parse_sbir_award_url_safe <- possibly(.parse_sbir_award_url, tibble())
# plan(multicore)

complete <-
  list.files() %>% str_remove_all(".rda") %>% as.integer()

sbirs <-
  df_awards %>%
  filter(!idSBIR %in% complete) %>%
  pull(idSBIR)

sbirs %>%
  future_walk(function(sbir) {
    url <-
      glue::glue("https://www.sbir.gov/sbirsearch/detail/{sbir}") %>% as.character()
    file <- glue::glue("{sbir}.rda")
    data <-
      .parse_sbir_award_url_safe(url = url, return_message = F)
    if (nrow(data) == 0) {
      return(invisible())
    }
    data %>% save(file = file)
  })
abresler/govtrackR documentation built on July 11, 2020, 12:30 a.m.