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
class WunderWeather.date.Observation(data, *args, **kwargs)[source]

Bases: WunderWeather.weather_base.WeatherBase

Wrapper for one date based data feature’s observations

date_pretty
temp_c
temp_f
class WunderWeather.date.Range(data, *args, **kwargs)[source]

Bases: WunderWeather.weather_base.WeatherBase

Wrapper for one (date) history type data feature response.

high_avg_temp_c
high_avg_temp_f
low_avg_temp_c
low_avg_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
class WunderWeather.forecast.Period(data, *args, **kwargs)[source]

Bases: WunderWeather.weather_base.WeatherBase

Wrapper for one Period in a forecast

date_pretty
high_temp_f
period
text
text_metric

WunderWeather.test module

class WunderWeather.test.TestAlerts(methodName='runTest')[source]

Bases: unittest.case.TestCase

setUp()[source]
test_get_item_count()[source]
test_get_one_item_data()[source]
class WunderWeather.test.TestAstronomy(methodName='runTest')[source]

Bases: unittest.case.TestCase

setUp()[source]
test_data_based_get()[source]
class WunderWeather.test.TestDate(methodName='runTest')[source]

Bases: unittest.case.TestCase

setUp()[source]
test_data_based_get()[source]
test_shorthand_based_get()[source]
test_shorthand_child_based_get()[source]
class WunderWeather.test.TestDaycast(methodName='runTest')[source]

Bases: unittest.case.TestCase

setUp()[source]
test_data_based_get()[source]
test_shorthand_based_get()[source]
test_shorthand_child_based_get()[source]
class WunderWeather.test.TestGeolookup(methodName='runTest')[source]

Bases: unittest.case.TestCase

setUp()[source]
test_data_based_get()[source]
class WunderWeather.test.TestHourlyDaycast(methodName='runTest')[source]

Bases: unittest.case.TestCase

setUp()[source]
test_get_item_count()[source]
test_get_one_item_data()[source]
class WunderWeather.test.TestHurricane(methodName='runTest')[source]

Bases: unittest.case.TestCase

setUp()[source]
test_data_based_get()[source]
class WunderWeather.test.TestRange(methodName='runTest')[source]

Bases: unittest.case.TestCase

setUp()[source]
test_data_based_get()[source]
test_shorthand_based_get()[source]
class WunderWeather.test.TestRawtide(methodName='runTest')[source]

Bases: unittest.case.TestCase

setUp()[source]
test_get_item_count()[source]
test_get_one_item_data()[source]
class WunderWeather.test.TestTide(methodName='runTest')[source]

Bases: unittest.case.TestCase

setUp()[source]
test_get_item_count()[source]
test_get_one_item_data()[source]
class WunderWeather.test.TestTodayHistorical(methodName='runTest')[source]

Bases: unittest.case.TestCase

setUp()[source]
test_data_based_get()[source]
test_shorthand_based_get()[source]
class WunderWeather.test.TestTodayNow(methodName='runTest')[source]

Bases: unittest.case.TestCase

setUp()[source]
test_data_based_get()[source]
test_shorthand_based_get()[source]
class WunderWeather.test.TestWeekcast(methodName='runTest')[source]

Bases: unittest.case.TestCase

setUp()[source]
test_data_based_get()[source]
test_shorthand_based_get()[source]
test_shorthand_child_based_get()[source]
class WunderWeather.test.TestYesterday(methodName='runTest')[source]

Bases: unittest.case.TestCase

setUp()[source]
test_data_based_get()[source]
test_shorthand_based_get()[source]
test_shorthand_child_based_get()[source]
WunderWeather.test.main()[source]
WunderWeather.test.run_snippet()[source]
WunderWeather.test.run_test()[source]

WunderWeather.test_responses module

WunderWeather.today module

class WunderWeather.today.Historical(data, *args, **kwargs)[source]

Bases: WunderWeather.weather_base.WeatherBase

Wrapper for one (today) almanac type data feature response.

high_avg_temp_c
high_avg_temp_f
low_avg_temp_c
low_avg_temp_f
class WunderWeather.today.Now(data, *args, **kwargs)[source]

Bases: WunderWeather.weather_base.WeatherBase

Wrapper for one (today) conditions type data feature response.

temp_c
temp_f
temp_pretty
weather

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

Wunderground Doc

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', 'daycast': 'forecast.Forecast', 'weekcast': 'forecast.Forecast', 'yesterday': 'date.Date', 'date': 'date.Date', 'hourly_weekcast': 'weather_base.WeatherBase', 'tide': 'weather_base.WeatherBase', 'hurricane': 'weather_base.WeatherBase', 'now': 'today.Now', 'geolookup': 'weather_base.WeatherBase', 'astronomy': 'weather_base.WeatherBase', 'cams': 'weather_base.WeatherBase', 'rawtide': 'weather_base.WeatherBase', 'satellite': 'weather_base.WeatherBase', 'today_historical': 'today.Historical', 'hourly_daycast': 'weather_base.WeatherBase', 'alerts': 'weather_base.WeatherBase'}
FEATURE_RESPONSE_MAP = {'date_range': 'trip', 'daycast': 'forecast', 'weekcast': 'forecast', 'yesterday': 'history', 'date': 'history', 'hourly_weekcast': 'hourly_forecast', 'tide': 'tide', 'hurricane': 'currenthurricane', 'now': 'current_observation', 'geolookup': 'location', 'astronomy': 'moon_phase', 'cams': 'webcams', 'rawtide': 'rawtide', 'satellite': 'satellite', 'today_historical': 'almanac', 'hourly_daycast': 'hourly_forecast', 'alerts': 'alerts'}
FEATURE_URL = 'http://api.wunderground.com/api/{key}/{features}/{settings}/q/{query}.{format}'
FEATURE_URL_MAP = {'date_range': 'planner_', 'daycast': 'forecast', 'weekcast': 'forecast10day', 'yesterday': 'yesterday', 'date': 'history_', 'hourly_weekcast': 'hourly10day', 'tide': 'tide', 'hurricane': 'currenthurricane', 'now': 'conditions', 'geolookup': 'geolookup', 'astronomy': 'astronomy', 'cams': 'webcams', 'rawtide': 'rawtide', 'satellite': 'satellite', 'today_historical': 'almanac', 'hourly_daycast': 'hourly', '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:
  • query (str or list) – string or list of strings for query portion of URL generation
  • date (str) – Date in the form YYYYMMDD.
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:
  • query (str or list) – string or list of strings for query portion of URL generation
  • date_range (str) – Date range (30 day max) in the form MMDDMMDD.
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 (str or list) – string or list of strings for query portion of URL generation
  • feature_context (tuple) – tuple of tuples to supply feature of interest and necessary data for that feature
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]
extract_value(keys)[source]

constructor to interface with feature response

Parameters:keys (list) – list of keys to drill down into nested dictionaries
Returns:value of interest or None

Module contents