-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscraper.R
39 lines (28 loc) · 1.07 KB
/
scraper.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Scraper for Vaccinate the States API. Queries every GeoJSON file and outputs the scraped data.
library(jsonlite)
library(dplyr)
library(tidyr)
library(readr)
# get state abbreviations
states <- state.abb
# build url for queries
baseurl <- "https://api.vaccinatethestates.com/v0/"
national_data <- data.frame()
for (i in 1:length(states)) {
# build URL for API query
state_url <- paste0(baseurl,states[i],".geojson")
# grab data for a single state
state_data <- fromJSON(state_url,flatten=TRUE)[["features"]]
for (j in 1:nrow(state_data)) {
# clean up the coordinates
state_data$longitude[j] <- strsplit(as.character(unlist(state_data$geometry.coordinates[j])), " ")[[1]]
state_data$latitude[j] <- strsplit(as.character(unlist(state_data$geometry.coordinates[j])), " ")[[2]]
}
# combine
national_data <- rbind(national_data,state_data)
cat(paste("Scraped data for state:",states[i],"\n"))
}
# write out time for diagnostic purposes
cat(paste("Scraper finished at",Sys.time()))
# write out the scraped data
write_csv(national_data,"vaccinatethestates.csv")