WunderWeather package¶
Submodules¶
WunderWeather.date module¶
-
class
WunderWeather.date.
Date
(data, *args, **kwargs)[source]¶ Bases:
WunderWeather.weather_base.WeatherBase
Wrapper for one (date) history type data feature response.
-
observations
¶ Abstract the observations for given date
Notes
In a date based response (History,Yesterday) there is a list of observations.
-
observations
list – List of dictionaries for each observation for the date
Returns: list of Observation instances -
-
temp_c
¶
-
temp_f
¶
-
WunderWeather.forecast module¶
-
class
WunderWeather.forecast.
Forecast
(data, *args, **kwargs)[source]¶ Bases:
WunderWeather.weather_base.WeatherBase
Wrapper for one Forecast-y type data feature response.
-
date
¶
-
periods
¶ Abstract the periods for given forecast
Notes
In a forecast response there are two list of dictionaries. One list is of text representations for each period and the other list is detailed data of each period. This member joins the two lists together, merging dictionaries of matching period keys. Each list is not always sorted in period increasing order and some periods may be missing from each list.
-
periods
defaultdict – of period data
-
txt_periods
¶ dict – list of dicts representing text period data
-
simple_periods
¶ dict – list of dict representing detailed period data
-
list_of_periods
¶ str – single list of period dicts for processing
-
period_dict
¶ dict – One period in a period list being processed
Returns: list of Period instances -
-
WunderWeather.test module¶
-
class
WunderWeather.test.
TestHourlyDaycast
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
-
class
WunderWeather.test.
TestTodayHistorical
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
WunderWeather.test_responses module¶
WunderWeather.today module¶
WunderWeather.weather module¶
-
class
WunderWeather.weather.
Extract
(api_key, settings=None)[source]¶ Bases:
object
Encapsulate logic for extracting weather data
This is the main point of entry to extract data from the weather underground service utilizing their public API.
Notes
- URL Request Format:
- http://api.wunderground.com/api/<API_KEY>/features/settings/q/query.format
-
BASE_URL
¶ str – Base string used for URL generation
-
FEATURE_URL
¶ str – string template to generate URL for a feature request
-
HURRICANE_URL
¶ str – string template to generate URL for a hurricane feature request
-
FEATURE_URL_MAP
¶ dict – Mapping of module’s feature key to wunderground’s key in the URL
-
FEATURE_RESPONSE_MAP
¶ dict – Mapping of module’s feature key to wunderground’s key in the response
-
FEATURE_CLASS_MAP
¶ dict – Mapping of module’s feature key to the object definition to generate an instance
-
BASE_URL
= 'http://api.wunderground.com/api'
-
FEATURE_CLASS_MAP
= {'date_range': 'date.Range', 'hurricane': 'weather_base.WeatherBase', 'astronomy': 'weather_base.WeatherBase', 'daycast': 'forecast.Forecast', 'hourly_daycast': 'weather_base.WeatherBase', 'yesterday': 'date.Date', 'weekcast': 'forecast.Forecast', 'date': 'date.Date', 'satellite': 'weather_base.WeatherBase', 'now': 'today.Now', 'rawtide': 'weather_base.WeatherBase', 'cams': 'weather_base.WeatherBase', 'today_historical': 'today.Historical', 'tide': 'weather_base.WeatherBase', 'hourly_weekcast': 'weather_base.WeatherBase', 'geolookup': 'weather_base.WeatherBase', 'alerts': 'weather_base.WeatherBase'}
-
FEATURE_RESPONSE_MAP
= {'date_range': 'trip', 'hurricane': 'currenthurricane', 'astronomy': 'moon_phase', 'daycast': 'forecast', 'hourly_daycast': 'hourly_forecast', 'yesterday': 'history', 'weekcast': 'forecast', 'date': 'history', 'satellite': 'satellite', 'now': 'current_observation', 'rawtide': 'rawtide', 'cams': 'webcams', 'today_historical': 'almanac', 'tide': 'tide', 'hourly_weekcast': 'hourly_forecast', 'geolookup': 'location', 'alerts': 'alerts'}
-
FEATURE_URL
= 'http://api.wunderground.com/api/{key}/{features}/{settings}/q/{query}.{format}'
-
FEATURE_URL_MAP
= {'date_range': 'planner_', 'hurricane': 'currenthurricane', 'astronomy': 'astronomy', 'daycast': 'forecast', 'hourly_daycast': 'hourly', 'yesterday': 'yesterday', 'weekcast': 'forecast10day', 'date': 'history_', 'satellite': 'satellite', 'now': 'conditions', 'rawtide': 'rawtide', 'cams': 'webcams', 'today_historical': 'almanac', 'tide': 'tide', 'hourly_weekcast': 'hourly10day', 'geolookup': 'geolookup', 'alerts': 'alerts'}
-
HURRICANE_URL
= 'http://api.wunderground.com/api/{key}/{feature}/{settings}/view.{format}'
-
alerts
(query)[source]¶ Shorthand to interface with the alerts data feature
Parameters: query (str or list) – string or list of strings for query portion of URL generation -
feature_context
¶ tuple – tuple of tuples to give feature of interest and necessary data for that feature
Returns: weather_base.WeatherBase instance or None -
-
astronomy
(query)[source]¶ Shorthand to interface with the astronomy data feature
Parameters: query (str or list) – string or list of strings for query portion of URL generation -
feature_context
tuple – tuple of tuples to give feature of interest and necessary data for that feature
Returns: weather_base.WeatherBase instance or None -
-
cams
(query)[source]¶ Shorthand to interface with the webcams data feature
Parameters: query (str or list) – string or list of strings for query portion of URL generation -
feature_context
tuple – tuple of tuples to give feature of interest and necessary data for that feature
Returns: weather_base.WeatherBase instance or None -
-
date
(query, date)[source]¶ Shorthand to interface with the history data feature
Parameters: -
feature_context
tuple – tuple of tuples to give feature of interest and necessary data for that feature
Returns: date.Date instance or None -
-
date_range
(query, date_range)[source]¶ Shorthand to interface with the planner data feature
Parameters: -
feature_context
tuple – tuple of tuples to give feature of interest
-
and necessary data for that feature
Returns: date.Range instance or None -
-
daycast
(query)[source]¶ Shorthand to interface with the forcast data feature
Parameters: query (str or list) – string or list of strings for query portion of URL generation -
feature_context
tuple – tuple of tuples to give feature of interest and necessary data for that feature
Returns: today.Now instance or None -
-
features
(query, feature_context)[source]¶ Central logic for making data feature requests
Parameters: -
query
¶ list – Strings for URL generation
-
feature_codes
¶ str – Final format for URL feature keys (with data appended)
-
context
¶ dict – final formatted data for URL template
-
response
¶ dict – JSON response
-
ctor
¶ obj – Object Class Reference to generate an instance. Could be one of
weather_base.WeatherBase
today.Now
today.Historical
forcast.Daycast
forcast.Weekcast
date.Date
date.Range
-
weather_features
¶ list – Instances to be retuned. Offset could be None if there was no response for the supplied data feature.
-
feature_key
¶ str – Module’s feature key
-
response_feature_key
¶ str – Module’s feature key for URL response
Returns: List of weather_features. Offsets returned in the order they are supplied in the feature_context arg. Offset could be none if no response -
-
geolookup
(query)[source]¶ Shorthand to interface with the geolookup data feature
Parameters: query (str or list) – string or list of strings for query portion of URL generation -
feature_context
tuple – tuple of tuples to give feature of interest and necessary data for that feature
Returns: weather_base.WeatherBase instance or None -
-
classmethod
get_feature_class
(feature_key)[source]¶ Get the class definition for a particular feature
Parameters: feature_key (str) – internal key for feature Returns: Class definition for feature
-
hourly_daycast
(query)[source]¶ Shorthand to interface with the hourly data feature
Parameters: query (str or list) – string or list of strings for query portion of URL generation -
feature_context
tuple – tuple of tuples to give feature of interest and necessary data for that feature
Returns: weather_base.WeatherBase instance or None -
-
hourly_weekcast
(query)[source]¶ Shorthand to interface with the hourly10day data feature
Parameters: query (str or list) – string or list of strings for query portion of URL generation -
feature_context
tuple – tuple of tuples to give feature of interest and necessary data for that feature
Returns: weather.Weather_Base instance or None -
-
hurricane
()[source]¶ Interface with the current hurricane data feature
-
feature_key
str – Module feature key
-
context
dict – Used to populate feature URL template
-
response
dict – JSON representation of the response
-
response_feature_key
str – Module feature key’s key for response parsing
-
ctor
weather.WeatherBase – Reference to class to potentially generate an instance
Returns: weather_base.WeatherBase instance or None -
-
rawtide
(query)[source]¶ Shorthand to interface with the rawtide data feature
Parameters: query (str or list) – string or list of strings for query portion of URL generation -
feature_context
tuple – tuple of tuples to give feature of interest and necessary data for that feature
Returns: weather_base.WeatherBase instance or None -
-
satellite
(query)[source]¶ Shorthand to interface with the satellite data feature
Parameters: query (str or list) – string or list of strings for query portion of URL generation -
feature_context
tuple – tuple of tuples to give feature of interest and necessary data for that feature
Returns: weather_base.WeatherBase instance or None -
-
tide
(query)[source]¶ Shorthand to interface with the tide data feature
Parameters: query (str or list) – string or list of strings for query portion of URL generation -
feature_context
tuple – tuple of tuples to give feature of interest and necessary data for that feature
Returns: weather_base.WeatherBase instance or None -
-
today_historical
(query)[source]¶ Shorthand to interface with the almanac data feature
Parameters: query (str or list) – string or list of strings for query portion of URL generation -
feature_context
tuple – tuple of tuples to give feature of interest and necessary data for that feature
Returns: today.Historical instance or None -
-
today_now
(query)[source]¶ Shorthand to interface with the conditions data feature
Parameters: query (str or list) – string or list of strings for query portion of URL generation -
feature_context
tuple – tuple of tuples to give feature of interest and necessary data for that feature
Returns: today.Now instance or None -
-
weekcast
(query)[source]¶ Shorthand to interface with the forcast10day data feature
Parameters: query (str or list) – string or list of strings for query portion of URL generation -
feature_context
tuple – tuple of tuples to give feature of interest and necessary data for that feature
Returns: forecast.Forecast instance or None -
-
yesterday
(query)[source]¶ Shorthand to interface with the yesterday data feature
Parameters: query (str or list) – string or list of strings for query portion of URL generation -
feature_context
tuple – tuple of tuples to give feature of interest and necessary data for that feature
Returns: date.Date instance or None -
WunderWeather.weather_base module¶
-
class
WunderWeather.weather_base.
WeatherBase
(data)[source]¶ Bases:
object
Wrapper for one all data feature responses.
-
data
¶ EasyDict – dictionary that allows for ‘dotted’ key references
-
__data
¶ dict – python dict, JSON representation of portion of response of interest
-
NAN
¶ list – list of values that are considered to be no data N/A type values
-
NAN
= [-999, -9999]
-