Moving from Wunderground to OpenWeatherMap

From Wunderground site:

The Weather Underground API has reached the end of service. To purchase access to the replacement API, please see our Weather Data Packages. If you are a contracted, paying customer and feel you have been shut off in error, please email feedback.wunderground@weather.com; be sure to include your name and API key.

My wunderground-powered weather dashboard) was sadly a victim of this change, and as for my personal use I don’t need the extended (paid) services or features offered in The Weather Company tiers, I had to look for a different option to enable back my dashboard.

In this reddit thread alternatives to wunderground have been suggested, I chose to migrate to OpenWeatherMap for the following:

  • Up to 60 calls per minute, but they recommend to keep as low as 1 per 10 minutes, which is OK for my usage
  • Simple and well-documented API
  • Descriptive weather condition mapped to id fields in the JSON payload, which makes it easier to build rules (although its numbering is a bit messy)

There are disadvantages or course:

  • Not as many weather stations as Wunderground, but I found at least 5 in Berlin and one of them was close to where I live
  • No feels-like temperature data, although it can be calculated.
  • Updates are slower than Wunderground, but as I plan to update every 10 minutes is fine

I imported the weather condition codes as a JSON, to allow later to map a given lighting setting to a weather status.

{
	"200": {
		"description": "thunderstorm with light rain",
		"action": "default"
	},
	"201": {
		"description": "thunderstorm with rain",
		"action": "default"
	},
	"202": {
		"description": "thunderstorm with heavy rain",
		"action": "default"
	}

As in my latest commit, I just needed to modify my previous constants:

OPENWEATHER_PATH    = "openweather.json"
OPENWEATHER_URL     = '/weather?id=2950159'

And update the getter and parser:

    openweather_states = get_file(OPENWEATHER_PATH)
    openweather_api = get_file(CRED_FILE_PATH)
    openweather_url = 'http://api.openweathermap.org/data/2.5/{0}&units=metric&appid={1}'.format(
        OPENWEATHER_URL, openweather_api['openweather'])

    r = requests.get(openweather_url).json()

    # build my dictionary array to write to database
    meas = {}
    meas['berlin_temperature'] = round(float(r['main']['temp']), 2)
    meas['berlin_humidity'] = round(float(r['main']['humidity']), 2)
    meas['weather_state'] = r['weather'][0]['description']
    meas['berlin_pressure'] = round(float(r['main']['pressure']), 2)
    meas['berlin_wind_speed_kph'] = round(float(r['wind']['speed']), 2)