.. This package and all of its contents are supplied "as-is" and follow the GNU General Public License https://www.gnu.org/licenses/gpl.txt Welcome to WunderWeather! ========================================= 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? .. contents:: :local: Introduction ************ 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. .. image:: _static/wundergroundLogo_4c_horz.jpg About the Wunderground API ########################## The Wunderground API supplies different endpoints called `data features `_ which, when supplied the proper arguments, return numerous data points describing the feature being queried. `Documentation `_ About the WunderWeather API ########################### 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 **Wunderground:** >>> response["history"]["daily_summary"]["meantempi"] **WunderWeather:** >>> response.temp_f #. 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 Installation ############ ``pip install WunderWeather`` Code Examples ############# 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``. .. warning:: The WunderWeather package is only Python 3 compatible. .. note:: 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! Weather Underground Example ---------------------------- **Not using Requests** *Example listed in Wunderground documentation* .. code-block:: python :linenos: import urllib2 import json f = urllib2.urlopen('http://api.wunderground.com/api//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 `_ **Using Requests** *Example listed in Wunderground doc converted to use requests* .. code-block:: python :linenos: import requests # learn more: https://python.org/pypi/requests response = requests.get('http://api.wunderground.com/api//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)) **Using WunderWeather** *Example listed in Wunderground doc converted to use WunderWeather* .. code-block:: python :linenos: from WunderWeather 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.* Additional Examples ------------------- .. code-block:: python :linenos: 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) Explore the WunderWeather API ############################# .. toctree:: :hidden: Home .. toctree:: :maxdepth: 2 modules Looking to Contribute ********************* 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. TODOs ####### #. 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. #. currenthurricane #. rawtide and tide #. hourly\* based features #. Of course, help with documentation, documentation, and more documentation. Mentions ******** I just want give mention and thanks to the following: #. `Weather Underground `_ for supplying the data. #. `requests `_ for making http for me. * `requests github `_ #. `EasyDict `_ for supplying the dotted dictionary notation functionality. * `EasyDict github `_ **Contributors:** `Tyler Santos `_ Indices and tables ================== * :ref:`genindex` * :ref:`modindex` * :ref:`search`