Last active
April 13, 2018 18:38
-
-
Save adam-garcia/cbc47ac7c02480b013b1a6ba6b19a0bb to your computer and use it in GitHub Desktop.
DarkSky Time Machine API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(glue) | |
library(httr) | |
library(jsonlite) | |
library(lubridate) | |
library(purrr) | |
token <- NA | |
base <- "https://api.darksky.net/forecast/{token}/" %>% | |
glue() %>% | |
str_c() | |
exclude <- "?exclude=currently,flags" | |
requests <- seq(as_datetime("2015-12-01 12:00:00", tz = "MST"), | |
as_datetime("2018-01-01 12:00:00", tz = "MST"), | |
by = "1 day") %>% | |
as.numeric() %>% | |
purrr::map(function(req_date){ | |
glue("{base}35.110833,-106.61,{req_date}") %>% | |
str_c() %>% | |
GET() | |
}) | |
weather_data <- requests %>% | |
map_df(function(resp){ | |
d <- content(resp) %>% | |
.$daily %>% | |
.$data | |
d %>% | |
unlist() %>% | |
t() %>% | |
as_tibble() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment