Using Forecast.io With GeekTool

Lately I’ve been feeling the itch to get back to honing my coding and scripting skills. The problem, for me, has always been that I have a very difficult time focusing on learning a language or toolset without a specific application to motivate me. To that end I decided recently that I would very much like to use Forecast.io’s public API to drive my GeekTool weather display.

For those who don’t know Forecast.io offers a public API with pretty generous terms for this sort of usage. Basically you get 1000 free API calls a day. That’s more than enough to update the weather every two minutes or so.

So, without further ado, here is my (extremely) quick and dirty Python script to pull down the local current weather conditions and display the summary and current temperature. I have GeekTool set to run this every 120 seconds. Fair warning, this script is amateur work to the point of silliness. I’m positive there are better ways to do pretty much all of it.

#! /usr/bin/python
# coding=utf-8
import json
import urllib
json_data=urllib.urlopen("https://api.forecast.io/<APIKEYGOESHERE>/<COORDINATESGOHERE>?exclude=minutely,hourly,daily,alerts,flags")
data=json.load(json_data)
strSummary=str(data["currently"]["summary"])
strTemp=str(round(data["currently"]["temperature"],1))
end="°F"
output=strSummary+', '+strTemp+end
print(output)

There you go. Comments are welcome, but dickishness will be met with extreme violence.