ywx 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,102 +1,154 @@
1
- = yahoo-weather
1
+ = YWx (Yahoo Weather) gem
2
2
 
3
- == About
3
+ Reliable weather data for your next project, and a great way to introduce APIs to new programmers.
4
4
 
5
- yahoo-weather provides an object-oriented interface to the Yahoo! Weather XML
6
- RSS feed detailed at http://developer.yahoo.com/weather.
5
+ == What Is This?
7
6
 
8
- People care a lot about the weather. This may seem ironic given they
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
- Log the weather information to your database! Graph it to your
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
- The RubyForge project page for this library is at
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 +rubygems+ if you don't already have it. See http://rubyforge.org/projects/rubygems/.
15
+ Install the gem by executing:
37
16
 
38
- Then install the gem by executing:
17
+ % gem install ywx
39
18
 
40
- % gem install yahoo-weather
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 'rubygems'
47
- require 'yahoo-weather'
48
-
49
- @client = YahooWeather::Client.new
50
- # look up WOEID via http://weather.yahoo.com; enter location by city
51
- # name or zip and WOEID is at end of resulting page url. herein we use
52
- # the WOEID for Santa Monica, CA.
53
- response = @client.lookup_by_woeid(2488892)
54
-
55
- # straight text output
56
- print <<edoc
57
- #{response.title}
58
- #{response.condition.temp} degrees
59
- #{response.condition.text}
60
- edoc
61
-
62
- # sample html output
63
- print <<edoc
64
- <div>
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
- Conditions for Santa Monica, CA at 10:51 am PST
78
- 56 degrees
79
- Partly Cloudy
80
- <div>
81
- <img src="http://l.yimg.com/a/i/us/nws/th/main_142b.gif"><br/>
82
- 56 degrees F<br/>
83
- Partly Cloudy<br>
84
- Forecast:<br/>
85
- Sat - Mostly Cloudy. High: 59 Low: 46<br/>
86
- Sun - Partly Cloudy. High: 64 Low: 48<br/>
87
- More information <a href="http://us.rd.yahoo.com/dailynews/rss/weather/Santa_Monica__CA/*http://weather.yahoo.com/forecast/USCA1024_f.html">here</a>.
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
- == License
94
-
95
- This library is provided via the GNU LGPL license at http://www.gnu.org/licenses/lgpl.html.
96
-
97
- == Author
98
-
99
- Copyright 2006 - 2009, Walter Korman <shaper@fatgoose.com>,
100
- http://lemurware.blogspot.com.
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.
@@ -1,7 +1,12 @@
1
- require_relative "lib/yahoo-weather.rb"
1
+ require_relative "../lib/ywx.rb"
2
2
  require "pp"
3
3
 
4
- @client = YahooWeather::Client.new('LM816I7V34HgjIFkSrFhatjTI6G1ksJFWwOTVOVOpSssTUFnpRI9iNIijbuQPOaOFR_Y_EmFbPXk03XF45uLqchthxBXWuw')
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
 
@@ -66,7 +66,7 @@ class YahooWeather::Client
66
66
  end
67
67
 
68
68
  def woe_lookup(zip)
69
- p ydata = HTTParty.get("http://where.yahooapis.com/v1/places.q('#{zip}')?appid=[#{@app_id}]")
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
@@ -22,7 +22,7 @@ require 'nokogiri'
22
22
  require "httparty"
23
23
 
24
24
  class YahooWeather
25
- VERSION = '0.1.2'
25
+ VERSION = '0.1.3'
26
26
 
27
27
  def self._parse_time (text)
28
28
  (text) ? Time.parse(text) : nil
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ywx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: