Getting the Weather

My good friend Warren Ellis (well complete stranger, but I read his newsletter so that is pretty the same thing) tweets pictures of where he is with the weather info overlaid. I am sure he is using some sort of newfangled social media filter to provide the info. I want something similar for the footnotes on my fairly post, but social media stuff is no good for me, I need an API to use.

Now, as hard as I try I cannot find a weather service that will just spit some data at me. I really want to do curl weathersite.internet | jq... and end up with a nice summary for a location. The web is closing up and locking down, which means an API key is required.

After putting this off for a while, this morning I remembered I have previously registered for a weather service. A steaming cup of coffee later and I found the python bindings to the excellent already installed.

import forecastio

api_key = "yer_key_here_bampot"
lat = 57.168
lng = -2.1055

forecast = forecastio.load_forecast(api_key, lat, lng)

weather = forecast.daily().data[0]

temperatureMax = int(weather.apparentTemperatureMax)
temperatureMin = int(weather.apparentTemperatureMin)
summary = weather.summary

print("{}°C {}".format(temperatureMax, summary))

Gives a nice

4°C Partly cloudy throughout the day.

There isn't anything to this, If I could find an API that didn't require a key I probably wouldn't even use python. But madness makes more madness, so here we are.

Reading: Cibola Burn, Virtual Light

Location: 57.168, -2.1055

Weather: 4°C Partly cloudy throughout the day.

Warren Ellis's was the main driver for me to start blogging everyday. I like to think I am being influenced by someone super productive, rather than blantently copying him.

blog morning

Posted on