Blog post banner

Detailed weather forecast in Excel using the Dark Sky API

April 12, 2018

The Dark Sky API allows you to look up the weather anywhere on the globe, returning (where available):

  • Current weather conditions
  • Minute-by-minute forecasts out to one hour
  • Hour-by-hour and day-by-day forecasts out to seven days
  • Hour-by-hour and day-by-day observations going back decades

Gridarrow makes it easy to integrate the Dark Sky data with Excel.

What is Gridarrow?

Gridarrow is the missing server for Excel. It connects just about any data source to Excel with simple Python scripts.
Why is it awesome?
  • It's real-time, so as soon as the data is updated in the Gridarrow App it's updated in Excel, no need to poll or refresh.
  • It's multi-user so your colleagues can connect to the same data at the same time.
  • It simplifies your spreadsheets by moving data retrieval and pre-processing into Python.
Request Demo

This example shows Excel receiving the detailed current, minutely, hourly, and daily weather forecasts for Washington D.C. (configured using lat/long coordinates).

dark sky data

Check out the Python code below to see how to connect Excel with the Dark Sky API

But before you jump into it, remember to:

 1 2 3 4 5 6 7 8 910111213141516171819202122232425262728
import os
from datetime import datetime
import forecastio
from gridarrow import Arrow

arrow = Arrow()

LATLONG = os.environ.get('LATLONG', "38.7128,-77.0060").split(",")

def currently(data):
    grid = arrow.grid('currently', rows=1, columns=data.keys())
    data['time'] = datetime.fromtimestamp(data['time'])
    grid[0, grid.columns] = [data[c] for c in grid.columns]

def build_grid(name, data):
    grid = arrow.grid(name, rows=len(data), columns=data[0].keys())
    for i, d in enumerate(data):
        d['time'] = datetime.fromtimestamp(d['time'])
        grid[i, grid.columns] = [d[col] if col in d else None
                                 for col in grid.columns]

@arrow.on_timer(duetime=0, period=3600)
def every_hour(_):
    forecast = forecastio.load_forecast(DARKSKY_KEY, *LATLONG)
    for resolution in ['minutely', 'hourly', 'daily']:
        build_grid(resolution, forecast.json[resolution]['data'])