Wrapper for Weather Underground API
Whether you’re already a user and want a refresher on the documentation or you’re evaluating the package for the first time, you’ve come to the right place. So what do you want to learn more about?
WunderWeather attempts to expose data supplied by Weather Underground in a way that is easy to use and easy to get weather data into your application quickly without having to deal with all of the details.
The Wunderground API supplies different endpoints called data features which, when supplied the proper arguments, return numerous data points describing the feature being queried.
WunderWeather was built to expose the data supplied by Wunderground in a uniform fashion. For certain data features where it applied, wrapper classes were created to normalize the data returned and supply ease of access to that data.
- When developing WunderWeather there were a few key concepts kept in mind which are listed below. If you intend on contributing, please keep these ideas in mind.
- Out of the hundreds of data points that Wunderground so graciously supplies, expose shortcuts to the more frequently used/popular data points such as temperature and date through the data feature specific wrappers.
- For the history data feature, Wunderground exposes the average temperature data point using 3 keys rather than the one abstracted in WunderWeather
- Normalize the data point names being exposed.
- The Wunderground API does a great job at supplying endless amounts of weather data but unfortunately similar data points across different features have different names. A case where this crops up frequently is for imperial (i) and metric (m) and their respective Fahrenheit (f) and Celsius (c) identifiers for temperature.
Example Data Points:
- temp_i vs temp_f
- temp_m vs temp_c
pip install WunderWeather
The following code snippets are examples of extracting data from data feature responses. Some examples build off of previous examples (as to avoid repetition) but should be properly documented as continuation from NNN example.
The WunderWeather package is only Python 3 compatible.
Because the requests package is awesome, we’re going to be using that to make our requests in the following examples. We use it to make requests in our package and so should you!
Not using Requests
Example listed in Wunderground documentation
import urllib2 import json f = urllib2.urlopen('http://api.wunderground.com/api/<YOUR_API_KEY>/geolookup/conditions/q/IA/Cedar_Rapids.json') json_string = f.read() parsed_json = json.loads(json_string) location = parsed_json['location']['city'] temp_f = parsed_json['current_observation']['temp_f'] print "Current temperature in %s is: %s" % (location, temp_f) f.close()
Example listed in Wunderground doc converted to use requests
import requests # learn more: https://python.org/pypi/requests response = requests.get('http://api.wunderground.com/api/<YOUR_API_KEY>/geolookup/conditions/q/MA/Boston.json').json() location = response['location']['city'] temp_f = response['current_observation']['temp_f'] print("Current Temperature in %s is: %s" %(location,temp_f))
Example listed in Wunderground doc converted to use WunderWeather
from wunder import weather extractor = weather.Extract(api_key) [location,current] = extractor.features("MA/Boston",(('geolookup',''),('now',''))) print("Current Temperature in %s is: %s" %(location.data.city,current.temp_f))
In the example above, notice how data points can be extracted from a feature using dotted notation whether there is a feature specific wrapper class or not to provide a uniform look in the calling application. When referencing shortcuts from wrapper classes or directly accessing the data, the look is the same. As of writing this documentation Geolookup does not have a wrapper so all data extracted from that feature must use the WeatherBase.data member to use the dotted notation.
From pprint import pprint import arrow From WunderWeather import weather # setup api_key = "your api key" location = 'MA/Boston' extractor = weather.Extract(api_key) # alerts response = extractor.alerts(location) pprint(response.data) # astronomy response = extractor.astronomy(location) pprint(response.data) # geolookup response = extractor.geolookup(location) pprint(response.data) # history date = arrow.get("20170601","YYYYMMDD") response = extractor.date(location,date.format('YYYYMMDD')) pprint(response.data) # addl date detail for observation in response.observations: print("Date:",observation.date_pretty) print("Temp:",observation.temp_f)
Thanks for checking out this section and showing interest in making this package better. The following are points of interest that could use polishing or expanding. As always, if you see data points across data features that could use a level of abstraction just add a wrapper class if not already defined and add a property member to that class to provide a shortcut or normalized external name across features.
- Several Data Features only exist using the generic WeatherBase, base class and thus their data is accessed using the data member. There are likely reasons to create wrappers for these features. current hurricane seemed to need a wrapper the most. But some others that might benefit from abstraction are listed below.
- rawtide and tide
- hourly* based features
- And of course, help with documentation, documentation, and more documentation.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size WunderWeather-1.1.0.tar.gz (29.0 kB)||File type Source||Python version None||Upload date||Hashes View hashes|