This module handles crawling, storing and retrieving of weather values.
It is split into two Classes.
|DemoWeather([env])||Gets Weathervalues from the database.|
|CurrentWeatherForecast([env, city])||Gets the current Weatherforecast from an online service.|
- get_temperature(env, date)¶
- env (BaseEnvironment) – the current environment
- date (datetime) – the time of which to retrieve the weather(forecast)
- class DemoWeather(env=None)¶
Gets Weathervalues from the database. The demo_mode operates on stored data from the past. For maximum realism, the past data should contain the real weather values as well as stored weather forecasts.
Retrieve a temperature at a certain time. The class will cache the values after the first query to speed up subsequent requests.
Parameters: date (datetime) – The time
Raises an Exception if there are no values in the database for the current time.
Retrieve a forecasted temperature at a certain time. The target_date must be between 0 and 10 days away from the creation_date, as weather forecasts only cover 10 days.
The class will cache the values after the first query to speed up subsequent requests.
Parameters: date (datetime) – The timepoint
- class CurrentWeatherForecast(env=None, city='Berlin')¶
Gets the current Weatherforecast from an online service. This is http://api.openweathermap.org/ at the moment, but may change in future versions.
Get the most accurate forecast for given date that can be derived from 5 days forecast, 14 days forecast or from history data. This is the public getter for forecasts and should be used
Parameters: date (datetime) – the timepoint for which to get the forecast Returns: temperature (float)
Get the hourly forecast for the given date.
get the forecast for given date. This only has day accuracy, but the forecast span is longer
returns a dictionary with city id, names and country based on the given search name the first search result is returned as ‘default’ too.
Parameters: name (string) – f.e. “Berlin”
retrieves an entire forecast. Tries to get forecast from internal list or filesystem cache. If that fails or data is too old, the online service will be queried
read from openweathermap. If this fails, use get_average_outside_temperature()
- get_average_outside_temperature(date, offset_days=0)¶
return an average Berlin temperature in 2012/2013 for a given date.
Parameters: offset_days (int) – offset the real days, f.e. to get some randomness