Skip to content

Instantly share code, notes, and snippets.

@adam-garcia
Last active April 13, 2018 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adam-garcia/cbc47ac7c02480b013b1a6ba6b19a0bb to your computer and use it in GitHub Desktop.
Save adam-garcia/cbc47ac7c02480b013b1a6ba6b19a0bb to your computer and use it in GitHub Desktop.
DarkSky Time Machine API
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