python-weather-api /

Filename Size Date modified Message
examples
473 B
1.1 KB
170 B
4.8 KB
9.0 KB
482 B
=Introduction=



The module provides a python wrapper around the Yahoo! Weather, Google Weather and NOAA APIs.



Author: Eugene Kaznacheev <qetzal@gmail.com>



(*pywapi* - Python Weather API)



=Building=



==From source ==



Download the latest pywapi library from: http://code.google.com/p/python-weather-api/





Untar the source distribution and run: 

{{{

  $ python setup.py build

  $ python setup.py install

}}}



=Getting the code=



View the trunk at: 

http://python-weather-api.googlecode.com/svn/trunk/



Check out the latest development version anonymously with: 

{{{

svn checkout http://python-weather-api.googlecode.com/svn/trunk/ python-weather-api-read-only

}}}



=Documentation=



== Yahoo! Weather ==

Use the following function, that fetches weather report from Yahoo



=== *pywapi.get_weather_from_yahoo(* _location_id_ *,* _ units = 'metric' _ *)* ===





*location_id*: A five digit US zip code or location ID. To find your location ID,

browse or search for your city from the Weather home page(http://weather.yahoo.com/)

The weather ID is in the URL for the forecast page for that city. You can also get the location ID by entering your zip code on the home page. For example, if you search for Los Angeles on the Weather home page, the forecast page for that city is http://weather.yahoo.com/forecast/USCA0638.html. The location ID is USCA0638.



*units*: type of units. 'metric' for metric and '' for  non-metric

Note that choosing metric units changes all the weather units to metric, for example, wind speed will be reported as kilometers per hour and barometric pressure as millibars.

Default value is 'metric'.



Returns:

*weather_data*: a dictionary of weather data that exists in XML feed. See http://developer.yahoo.com/weather/#channel



 * [ExampleOfYahooXML Example of XML responce from Yahoo]

 * [Examples#Yahoo!_Weather Example of return data]







== Google Weather ==



Use the following function, that fetches weather report from Google



=== *pywapi.get_weather_from_google(* _location_id_ *,* _ hl = '' _ *)* ===



*location_id*: a zip code (10001); city name, state (weather=woodland,PA); city name, country (weather=london,england); or possibly others.



*hl*: the language parameter (language code)



Returns:

*weather_data*: a dictionary of weather data that exists in XML feed. [ExampleOfGoogleWeatherXML Example of XML responce from Google]



 * [ExampleOfGoogleWeatherXML Example of XML responce from Google]

 * [Examples#Google_Weather Example of return data]





== NOAA ==

Use the following function, that fetches weather report from NOAA: National Oceanic and Atmospheric Administration (United States)



=== *pywapi.get_weather_from_noaa(* _station_id_ *)* ===



*station_id*: the ID of the weather station near the necessary location



To find your station ID, perform the following steps:

 # Open this URL: http://www.weather.gov/xml/current_obs/seek.php?state=az&Find=Find

 # Select the necessary state state. Click 'Find'.

 # Find the necessary station in the 'Observation Location' column.

 # The station ID is in the URL for the weather page for that station.



For example if the weather page is http://weather.noaa.gov/weather/current/KPEO.html -- the station ID is KPEO.



Other way to get the station ID: use this library: http://code.google.com/p/python-weather/ and _Weather.location2station_ function.



Returns:

*weather_data*: a dictionary of weather data that exists in XML feed. 

[ExampleOfNoaaXML Example of XML responce from NOAA]



 * [ExampleOfNoaaXML Example of XML responce from NOAA]

 * [Examples#NOAA Example of return data]



(useful icons: http://www.weather.gov/xml/current_obs/weather.php)







=Examples=



===[Examples More examples]===



==Script==

{{{

import  pywapi

import string



google_result = pywapi.get_weather_from_google('10001')

yahoo_result = pywapi.get_weather_from_yahoo('10001')

noaa_result = pywapi.get_weather_from_noaa('KJFK')



print "Google says: It is " + string.lower(google_result['current_conditions']['condition']) + " and " + google_result['current_conditions']['temp_c'] + "C now in New York.\n\n"



print "Yahoo says: It is " + string.lower(yahoo_result['condition']['text']) + " and " + yahoo_result['condition']['temp'] + "C now in New York.\n\n"



print "NOAA says: It is " + string.lower(noaa_result['weather']) + " and " + noaa_result['temp_c'] + "C now in New York.\n"

}}}



==Result==

{{{

[~] python examples/pywapi-example.py



Google says: It is overcast and 15C now in New York.



Yahoo says: It is fog and 14C now in New York.



NOAA says: It is overcast and 15C now in New York.



}}}



= TODO =



 * unit tests

 * http://www.weather.com/

 * http://wiki.wunderground.com/index.php/API_-_XML

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.