ywx 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +132 -80
- data/examples/demo.rb +7 -2
- data/lib/yahoo-weather/client.rb +1 -1
- data/lib/ywx.rb +1 -1
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -1,102 +1,154 @@
|
|
1
|
-
=
|
1
|
+
= YWx (Yahoo Weather) gem
|
2
2
|
|
3
|
-
|
3
|
+
Reliable weather data for your next project, and a great way to introduce APIs to new programmers.
|
4
4
|
|
5
|
-
|
6
|
-
RSS feed detailed at http://developer.yahoo.com/weather.
|
5
|
+
== What Is This?
|
7
6
|
|
8
|
-
|
9
|
-
can just glance out the window. However, we can all understand a
|
10
|
-
fascination with details and forecasting.
|
7
|
+
YWx provides a Ruby interface to the Yahoo Weather XML RSS feed detailed at http://developer.yahoo.com/weather.
|
11
8
|
|
12
|
-
|
13
|
-
heart's content! Write a widget that emails the weather to your cell
|
14
|
-
phone every five minutes with a link to your friend's PayPal account
|
15
|
-
to deposit money if the weather's sunny and you both bet that it would
|
16
|
-
be rainy. And the fun doesn't have to stop there.
|
9
|
+
Weather data is exciting. Its broad in scope, yet very practical in everyday implementation. Most important, it's a perfect dataset for young programmers to begin interacting with. The Yahoo Weather API is a particularly easy way to start working with outside data.
|
17
10
|
|
18
|
-
|
19
|
-
http://rubyforge.org/projects/yahoo-weather.
|
20
|
-
|
21
|
-
Source code is at http://github.com/shaper/yahoo-weather.
|
22
|
-
|
23
|
-
NOTE: This library was updated as of December 2009 to use a new
|
24
|
-
WOEID-based lookup interface. Yahoo has deprecated the older
|
25
|
-
non-WOEID-based lookup API. The archived page with the deprecated API
|
26
|
-
details is at:
|
27
|
-
|
28
|
-
http://developer.yahoo.com/weather/archive.html
|
29
|
-
|
30
|
-
The older interface is still operational but users of this library
|
31
|
-
should shift from using YahooWeather::Client::lookup_location to
|
32
|
-
YahooWeather::Client::lookup_by_woeid.
|
11
|
+
Log the weather information to your database! Graph it to your heart's content! Write a widget that emails the weather to your cell phone. There are lots of opportunities to learn and experiment.
|
33
12
|
|
34
13
|
== Installation
|
35
14
|
|
36
|
-
Install
|
15
|
+
Install the gem by executing:
|
37
16
|
|
38
|
-
|
17
|
+
% gem install ywx
|
39
18
|
|
40
|
-
|
19
|
+
Then, apply for a Yahoo GeoPlanet Application ID at http://developer.yahoo.com/geo/geoplanet/
|
20
|
+
|
21
|
+
The application is free, easy and fast.
|
41
22
|
|
42
23
|
== Usage
|
43
24
|
|
44
25
|
A simple example program:
|
45
26
|
|
46
|
-
require '
|
47
|
-
require '
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
#
|
63
|
-
|
64
|
-
|
65
|
-
<img src="#{response.image.url}"><br/>
|
66
|
-
#{response.condition.temp} degrees #{response.units.temperature}<br/>
|
67
|
-
#{response.condition.text}<br>
|
68
|
-
Forecast:<br/>
|
69
|
-
#{response.forecasts[0].day} - #{response.forecasts[0].text}. High: #{response.forecasts[0].high} Low: #{response.forecasts[0].low}<br/>
|
70
|
-
#{response.forecasts[1].day} - #{response.forecasts[1].text}. High: #{response.forecasts[1].high} Low: #{response.forecasts[1].low}<br/>
|
71
|
-
More information <a href="#{response.page_url}">here</a>.
|
72
|
-
</div>
|
73
|
-
edoc
|
74
|
-
|
27
|
+
require 'ywx'
|
28
|
+
require 'pp'
|
29
|
+
appid = 'INSERT_YAHOO_APPID_HERE'
|
30
|
+
|
31
|
+
@client = YahooWeather::Client.new(appid)
|
32
|
+
|
33
|
+
response = @client.lookup_zip(73072)
|
34
|
+
pp "Info"
|
35
|
+
pp response.title
|
36
|
+
pp response.condition.temp
|
37
|
+
pp response.condition.text
|
38
|
+
pp "Conditions"
|
39
|
+
pp response.condition.temp
|
40
|
+
pp response.units.temperature
|
41
|
+
pp response.condition.text
|
42
|
+
pp "Forecast"
|
43
|
+
pp "#{response.forecasts[0].day} - #{response.forecasts[0].text}. High: #{response.forecasts[0].high} Low: #{res
|
44
|
+
pp "#{response.forecasts[1].day} - #{response.forecasts[1].text}. High: #{response.forecasts[1].high} Low: #{res
|
45
|
+
|
75
46
|
Produces output as:
|
76
47
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
</div>
|
48
|
+
"Info"
|
49
|
+
"Conditions for Norman, OK at 4:54 pm CDT"
|
50
|
+
84
|
51
|
+
"Mostly Cloudy"
|
52
|
+
"Conditions"
|
53
|
+
84
|
54
|
+
"F"
|
55
|
+
"Mostly Cloudy"
|
56
|
+
"Forecast"
|
57
|
+
"Mon - Scattered Thunderstorms. High: 78 Low: 67"
|
58
|
+
"Tue - Partly Cloudy/Wind. High: 85 Low: 69"
|
89
59
|
|
90
60
|
There is a variety of detailed weather information in other attributes of the
|
91
61
|
YahooWeather::Response object.
|
92
62
|
|
93
|
-
==
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
63
|
+
== Full Data Readout
|
64
|
+
|
65
|
+
For a full display of all the available data in the request, run the following code
|
66
|
+
|
67
|
+
require 'ywx'
|
68
|
+
require 'pp'
|
69
|
+
appid = 'INSERT_YAHOO_APPID_HERE'
|
70
|
+
|
71
|
+
@client = YahooWeather::Client.new(appid)
|
72
|
+
|
73
|
+
pp response = @client.lookup_zip(73072)
|
74
|
+
|
75
|
+
This produces a readout like the following:
|
76
|
+
|
77
|
+
#<YahooWeather::Response:0x007fc55c942090
|
78
|
+
@astronomy=
|
79
|
+
#<YahooWeather::Astronomy:0x007fc55c93fde0
|
80
|
+
@sunrise=2012-04-30 06:37:00 -0500,
|
81
|
+
@sunset=2012-04-30 20:14:00 -0500>,
|
82
|
+
@atmosphere=
|
83
|
+
#<YahooWeather::Atmosphere:0x007fc55c91aa90
|
84
|
+
@barometer="steady",
|
85
|
+
@humidity=58,
|
86
|
+
@pressure=29.88,
|
87
|
+
@visibility=10>,
|
88
|
+
@condition=
|
89
|
+
#<YahooWeather::Condition:0x007fc55c902440
|
90
|
+
@code=28,
|
91
|
+
@date=2012-04-30 16:54:00 -0500,
|
92
|
+
@temp=84,
|
93
|
+
@text="Mostly Cloudy">,
|
94
|
+
@description=
|
95
|
+
"\n<img src=\"http://l.yimg.com/a/i/us/we/52/28.gif\"/><br />\n<b>Current Conditions:</b><br />\nMostly Cloudy, 84 F<BR />\n<BR /><b>Forecast:</b><BR />\nMon - Scattered Thunderstorms. High: 78 Low: 67<br />\nTue - Partly Cloudy/Wind. High: 85 Low: 69<br />\n<br />\n<a href=\"http://us.rd.yahoo.com/dailynews/rss/weather/Norman__OK/*http://weather.yahoo.com/forecast/USOK0388_f.html\">Full Forecast at Yahoo! Weather</a><BR/><BR/>\n(provided by <a href=\"http://www.weather.com\" >The Weather Channel</a>)<br/>\n",
|
96
|
+
@forecasts=
|
97
|
+
[#<YahooWeather::Forecast:0x007fc55c8e33d8
|
98
|
+
@code=47,
|
99
|
+
@date=2012-04-30 00:00:00 -0500,
|
100
|
+
@day="Mon",
|
101
|
+
@high=78,
|
102
|
+
@low=67,
|
103
|
+
@text="Scattered Thunderstorms">,
|
104
|
+
#<YahooWeather::Forecast:0x007fc55c8d5a58
|
105
|
+
@code=24,
|
106
|
+
@date=2012-05-01 00:00:00 -0500,
|
107
|
+
@day="Tue",
|
108
|
+
@high=85,
|
109
|
+
@low=69,
|
110
|
+
@text="Partly Cloudy/Wind">],
|
111
|
+
@image=
|
112
|
+
#<YahooWeather::Image:0x007fc55c9180d8
|
113
|
+
@height=18,
|
114
|
+
@link="http://weather.yahoo.com",
|
115
|
+
@title="Yahoo! Weather",
|
116
|
+
@url="http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif",
|
117
|
+
@width=142>,
|
118
|
+
@latitude=35.22,
|
119
|
+
@location=
|
120
|
+
#<YahooWeather::Location:0x007fc55c924a40
|
121
|
+
@city="Norman",
|
122
|
+
@country="United States",
|
123
|
+
@region="OK">,
|
124
|
+
@longitude=-97.51,
|
125
|
+
@page_url=
|
126
|
+
"http://us.rd.yahoo.com/dailynews/rss/weather/Norman__OK/*http://weather.yahoo.com/forecast/USOK0388_f.html",
|
127
|
+
@request_location="12789594",
|
128
|
+
@request_url="http://weather.yahooapis.com/forecastrss?w=12789594&u=f",
|
129
|
+
@title="Conditions for Norman, OK at 4:54 pm CDT",
|
130
|
+
@units=
|
131
|
+
#<YahooWeather::Units:0x007fc55c922d80
|
132
|
+
@distance="mi",
|
133
|
+
@pressure="in",
|
134
|
+
@speed="mph",
|
135
|
+
@temperature="F">,
|
136
|
+
@wind=
|
137
|
+
#<YahooWeather::Wind:0x007fc55c9207d8
|
138
|
+
@chill=84,
|
139
|
+
@direction=170,
|
140
|
+
@speed=14>>
|
141
|
+
|
142
|
+
The the specific data points are easy to access. For example, if you wanted the forecasted high temperature for tomorrow, use the following line.
|
143
|
+
|
144
|
+
response.forecasts[1].high
|
145
|
+
|
146
|
+
Or if you wanted to isolate the latitude and longitude of the reading station, simply run the following
|
147
|
+
|
148
|
+
response.latitude
|
149
|
+
response.longitude
|
150
|
+
|
151
|
+
Its that easy. Start building something.
|
152
|
+
|
153
|
+
Thanks, and happy hacking.
|
101
154
|
|
102
|
-
Thanks to Matthew Berk for inspiration and initial hack.
|
data/examples/demo.rb
CHANGED
@@ -1,7 +1,12 @@
|
|
1
|
-
require_relative "lib/
|
1
|
+
require_relative "../lib/ywx.rb"
|
2
2
|
require "pp"
|
3
3
|
|
4
|
-
|
4
|
+
#Get your API key here(http://developer.yahoo.com/)
|
5
|
+
#Its free and easy
|
6
|
+
|
7
|
+
appid = 'INSERT_YAHOO_APP_ID_HERE'
|
8
|
+
|
9
|
+
@client = YahooWeather::Client.new(appid)
|
5
10
|
|
6
11
|
response = @client.lookup_zip(73072)
|
7
12
|
|
data/lib/yahoo-weather/client.rb
CHANGED
@@ -66,7 +66,7 @@ class YahooWeather::Client
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def woe_lookup(zip)
|
69
|
-
|
69
|
+
ydata = HTTParty.get("http://where.yahooapis.com/v1/places.q('#{zip}')?appid=[#{@app_id}]")
|
70
70
|
woe_id = ydata["places"]["place"]["woeid"]
|
71
71
|
end
|
72
72
|
|
data/lib/ywx.rb
CHANGED