dubwoc / python-weather-api

Automatically exported from code.google.com/p/python-weather-api
MIT License
0 stars 0 forks source link

Yahoo! Weather works only with weather.com ID instead of WOEID #32

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What version of the product are you using? On what operating system?

pywapi-0.3.6

Please provide any additional information below.

>>> import pywapi
>>> pywapi.get_weather_from_yahoo('2502265', units='metric')
{'error': u'City not found'}
>>> pywapi.get_location_ids('Sunnyvale')
{u'USNC4980': u'Sunnyvale, NC', u'USCA1116': u'Sunnyvale, CA', u'USCO1607': 
u'Sunnyvale, CO', u'USTX1319': u'Sunnyvale, TX', u'NZXX2873': u'Sunnyvale, OTA, 
New Zealand', u'USMO3789': u'Sunnyvale, MO', u'USUT2816': u'Sunnyvale Heights, 
UT', u'USUT2817': u'Sunnyvale Park, UT'}
>>> pywapi.get_weather_from_yahoo('USCA1116', units='metric')
{'html_description': u'\n<img src="http://l.yimg.com/a/i/us/we/52/26.gif"/><br 
/>\n<b>Current Conditions:</b><br />\nCloudy, 13 C<BR />\n<BR 
/><b>Forecast:</b><BR />\nSun - Partly Cloudy. High: 18 Low: 11<br />\nMon - 
Mostly Sunny. High: 16 Low: 8<br />\nTue - Partly Cloudy. High: 17 Low: 8<br 
/>\nWed - Partly Cloudy. High: 17 Low: 8<br />\nThu - Sunny. High: 21 Low: 9<br 
/>\n<br />\n<a 
href="http://us.rd.yahoo.com/dailynews/rss/weather/Sunnyvale__CA/*http://weather
.yahoo.com/forecast/USCA1116_c.html">Full Forecast at Yahoo! 
Weather</a><BR/><BR/>\n(provided by <a href="http://www.weather.com" >The 
Weather Channel</a>)<br/>\n', 'atmosphere': {'pressure': u'1015.8', 'rising': 
u'2', 'visibility': u'14.48', 'humidity': u'80'}, 'title': u'Yahoo! Weather - 
Sunnyvale, CA', 'condition': {'date': u'Sun, 27 Oct 2013 9:56 am PDT', 'text': 
u'Cloudy', 'code': u'26', 'temp': u'13', 'title': u'Conditions for Sunnyvale, 
CA at 9:56 am PDT'}, 'forecasts': [{'code': u'30', 'text': u'Partly Cloudy', 
'high': u'18', 'low': u'11', 'date': u'27 Oct 2013', 'day': u'Sun'}, {'code': 
u'34', 'text': u'Mostly Sunny', 'high': u'16', 'low': u'8', 'date': u'28 Oct 
2013', 'day': u'Mon'}, {'code': u'30', 'text': u'Partly Cloudy', 'high': u'17', 
'low': u'8', 'date': u'29 Oct 2013', 'day': u'Tue'}, {'code': u'30', 'text': 
u'Partly Cloudy', 'high': u'17', 'low': u'8', 'date': u'30 Oct 2013', 'day': 
u'Wed'}, {'code': u'32', 'text': u'Sunny', 'high': u'21', 'low': u'9', 'date': 
u'31 Oct 2013', 'day': u'Thu'}], 'link': 
u'http://us.rd.yahoo.com/dailynews/rss/weather/Sunnyvale__CA/*http://weather.yah
oo.com/forecast/USCA1116_c.html', 'location': {'city': u'Sunnyvale', 'region': 
u'CA', 'country': u'US'}, 'units': {'distance': u'km', 'speed': u'km/h', 
'temperature': u'C', 'pressure': u'mb'}, 'astronomy': {'sunset': u'6:15 pm', 
'sunrise': u'7:26 am'}, 'geo': {'lat': u'37.39', 'long': u'-122.03'}, 'wind': 
{'direction': u'110', 'speed': u'8.05', 'chill': u'13'}}
>>> pywapi.get_weather_from_weather_com('USCA1116', units='metric')
{'units': {'distance': u'km', 'speed': u'km/h', 'temperature': u'C', 
'rainfall': u'mm', 'pressure': u'mb'}, 'current_conditions': {'moon_phase': 
{'text': u'Last Quarter', 'icon': u'22'}, 'last_updated': u'10/27/13 10:05 AM 
PDT', 'temperature': u'13', 'dewpoint': u'9', 'text': u'Cloudy', 'uv': 
{'index': u'1', 'text': u'Low'}, 'visibility': u'14.5', 'humidity': u'80', 
'station': u'Moffett Field, CA, US', 'barometer': {'direction': u'falling', 
'reading': u'1015.58'}, 'feels_like': u'13', 'wind': {'gust': u'N/A', 
'direction': u'110', 'speed': u'8', 'text': u'ESE'}, 'icon': u'26'}, 
'location': {'lat': u'37.37', 'lon': u'-122.03', 'name': u'Sunnyvale, CA'}, 
'forecasts': [{'day_of_week': u'Sunday', 'high': u'18', 'sunset': u'9:15 PM', 
'low': u'11', 'night': {'brief_text': u'P Cloudy', 'text': u'Partly Cloudy', 
'chance_precip': u'20', 'humidity': u'78', 'wind': {'gust': u'N/A', 
'direction': u'270', 'speed': u'23', 'text': u'W'}, 'icon': u'29'}, 'date': 
u'Oct 27', 'day': {'brief_text': u'P Cloudy', 'text': u'Partly Cloudy', 
'chance_precip': u'0', 'humidity': u'65', 'wind': {'gust': u'N/A', 'direction': 
u'314', 'speed': u'18', 'text': u'NW'}, 'icon': u'30'}, 'sunrise': u'10:28 
AM'}, {'day_of_week': u'Monday', 'high': u'16', 'sunset': u'9:15 PM', 'low': 
u'8', 'night': {'brief_text': u'M Clear', 'text': u'Mostly Clear', 
'chance_precip': u'10', 'humidity': u'84', 'wind': {'gust': u'N/A', 
'direction': u'206', 'speed': u'13', 'text': u'SSW'}, 'icon': u'33'}, 'date': 
u'Oct 28', 'day': {'brief_text': u'M Sunny', 'text': u'Mostly Sunny', 
'chance_precip': u'20', 'humidity': u'74', 'wind': {'gust': u'N/A', 
'direction': u'296', 'speed': u'18', 'text': u'WNW'}, 'icon': u'34'}, 
'sunrise': u'10:28 AM'}, {'day_of_week': u'Tuesday', 'high': u'17', 'sunset': 
u'9:15 PM', 'low': u'8', 'night': {'brief_text': u'M Clear', 'text': u'Mostly 
Clear', 'chance_precip': u'0', 'humidity': u'73', 'wind': {'gust': u'N/A', 
'direction': u'343', 'speed': u'3', 'text': u'NNW'}, 'icon': u'33'}, 'date': 
u'Oct 29', 'day': {'brief_text': u'P Cloudy', 'text': u'Partly Cloudy', 
'chance_precip': u'0', 'humidity': u'72', 'wind': {'gust': u'N/A', 'direction': 
u'232', 'speed': u'11', 'text': u'SW'}, 'icon': u'30'}, 'sunrise': u'10:28 
AM'}, {'day_of_week': u'Wednesday', 'high': u'17', 'sunset': u'9:15 PM', 'low': 
u'8', 'night': {'brief_text': u'Clear', 'text': u'Clear', 'chance_precip': 
u'0', 'humidity': u'59', 'wind': {'gust': u'N/A', 'direction': u'118', 'speed': 
u'5', 'text': u'ESE'}, 'icon': u'31'}, 'date': u'Oct 30', 'day': {'brief_text': 
u'P Cloudy', 'text': u'Partly Cloudy', 'chance_precip': u'0', 'humidity': 
u'53', 'wind': {'gust': u'N/A', 'direction': u'18', 'speed': u'14', 'text': 
u'NNE'}, 'icon': u'30'}, 'sunrise': u'10:28 AM'}, {'day_of_week': u'Thursday', 
'high': u'21', 'sunset': u'9:15 PM', 'low': u'9', 'night': {'brief_text': 
u'Clear', 'text': u'Clear', 'chance_precip': u'0', 'humidity': u'55', 'wind': 
{'gust': u'N/A', 'direction': u'5', 'speed': u'5', 'text': u'N'}, 'icon': 
u'31'}, 'date': u'Oct 31', 'day': {'brief_text': u'Sunny', 'text': u'Sunny', 
'chance_precip': u'0', 'humidity': u'50', 'wind': {'gust': u'N/A', 'direction': 
u'12', 'speed': u'13', 'text': u'NNE'}, 'icon': u'32'}, 'sunrise': u'10:28 
AM'}]}

Original issue reported on code.google.com by hector.v...@gmail.com on 27 Oct 2013 at 5:36

GoogleCodeExporter commented 8 years ago
As it is implemented now, the URL for location ID is:
http://weather.yahooapis.com/forecastrss?u=c&p=USCA1116

The equivalent URL for WOEID would be:
http://weather.yahooapis.com/forecastrss?u=c&w=2502265

At the moment pywapi parses the XML data directly; it is now possible using YQL 
to obtain the same data in JSON which would be much easier to parse.

The equivalent URLs for JSON data to the ones above are:
For location id:
http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%
20where%20location%3D%22USCA1116%22%20and%20u%3D%22c%22&format=json

And for WOEID:
http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%
20where%20woeid%3D2502265%20and%20u%3D%22c%22&format=json

Original comment by jtas...@gmail.com on 8 Feb 2014 at 1:34