noaa-weather 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/bin/noaa-weather +4 -4
- data/lib/noaa-weather.rb +58 -7
- data/spec/noaa-weather.spec +9 -2
- metadata +2 -2
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
data/bin/noaa-weather
CHANGED
@@ -11,12 +11,12 @@ OptionParser.new do |opts|
|
|
11
11
|
options[:site] = s
|
12
12
|
end
|
13
13
|
|
14
|
-
opts.on(:REQUIRED,"-
|
15
|
-
options[:lat]=
|
14
|
+
opts.on(:REQUIRED,"-t","--lattitude","find weather by lat/lng (requires -b)") do |t|
|
15
|
+
options[:lat]=t
|
16
16
|
end
|
17
17
|
|
18
|
-
opts.on(:REQUIRED,"-
|
19
|
-
options[:lng]=
|
18
|
+
opts.on(:REQUIRED,"-g","--longititude","find wather by lat/lng (requires -t)") do |g|
|
19
|
+
options[:lng]=g
|
20
20
|
end
|
21
21
|
|
22
22
|
end.parse!
|
data/lib/noaa-weather.rb
CHANGED
@@ -55,8 +55,8 @@ class CachedGeocode
|
|
55
55
|
end
|
56
56
|
|
57
57
|
class Noaaweather < CachedGeocode
|
58
|
-
VERSION = '0.1.
|
59
|
-
attr_accessor :lattitude,:longitude, :start_time
|
58
|
+
VERSION = '0.1.5'
|
59
|
+
attr_accessor :lattitude,:longitude, :start_time, :conditions
|
60
60
|
|
61
61
|
def initialize(site,as_address=false)
|
62
62
|
|
@@ -88,12 +88,28 @@ class Noaaweather < CachedGeocode
|
|
88
88
|
|
89
89
|
def current_conditions(ashash=false)
|
90
90
|
|
91
|
-
self.
|
92
|
-
|
93
|
-
|
94
|
-
|
91
|
+
self.forecast if self.conditions.nil?
|
92
|
+
if Time.now.strftime("%H").to_i < 6 or Time.now.strftime("%H").to_i > 18
|
93
|
+
if ashash
|
94
|
+
self.forecast['Tonight']
|
95
|
+
else
|
96
|
+
@ccond ||= sprintf("%s, High of %i, Low of %i and %s",'Tonight',self.forecast['Tonight'][:high],
|
97
|
+
self.forecast['Tonight'][:low], self.forecast['Tonight'][:conditions])
|
98
|
+
end
|
99
|
+
elsif Time.now.strftime("%H").to_i < 18
|
100
|
+
if ashash
|
101
|
+
self.forecast['Today']
|
102
|
+
else
|
103
|
+
@ccond ||= sprintf("%s, High of %i, Low of %i and %s",'Today',self.forecast['Today'][:high],
|
104
|
+
self.forecast['Today'][:low], self.forecast['Today'][:conditions])
|
105
|
+
end
|
95
106
|
else
|
96
|
-
|
107
|
+
if ashash
|
108
|
+
self.forecast['Today']
|
109
|
+
else
|
110
|
+
@ccond ||= sprintf("%s, High of %i, Low of %i and %s",'Today',self.forecast['Today'][:high],
|
111
|
+
self.forecast['Today'][:low], self.forecast['Today'][:conditions])
|
112
|
+
end
|
97
113
|
end
|
98
114
|
end
|
99
115
|
|
@@ -110,6 +126,24 @@ class Noaaweather < CachedGeocode
|
|
110
126
|
@doc = fetch_from_noaa
|
111
127
|
end
|
112
128
|
|
129
|
+
def forecast
|
130
|
+
@forecast = fetch_forecast_from_noaa
|
131
|
+
@forecast.find('/dwml/data/time-layout')
|
132
|
+
_when = @forecast.find('/dwml/data/time-layout')[2].find('start-valid-time').collect {|x| x['period-name'] }[0..5]
|
133
|
+
_daily_maxt = @forecast.find('/dwml/data/parameters/temperature')[0].find('value').collect {|x| x.content }[0..2]
|
134
|
+
_daily_mint = @forecast.find('/dwml/data/parameters/temperature')[1].find('value').collect {|x| x.content }[0..2]
|
135
|
+
_weather = @forecast.find('/dwml/data/parameters/weather/weather-conditions').collect {|x| x['weather-summary'] }[0..5]
|
136
|
+
count = 0
|
137
|
+
sub_count = 0
|
138
|
+
_dat = {}
|
139
|
+
while count < 6
|
140
|
+
_dat[_when[count]] = {:high => _daily_maxt[sub_count.floor], :low => _daily_mint[sub_count.floor], :conditions => _weather[count] }
|
141
|
+
count += 1
|
142
|
+
sub_count += 0.5
|
143
|
+
end
|
144
|
+
self.conditions = _dat
|
145
|
+
end
|
146
|
+
|
113
147
|
private
|
114
148
|
def fetch_from_noaa
|
115
149
|
|
@@ -125,11 +159,28 @@ class Noaaweather < CachedGeocode
|
|
125
159
|
par = XML::Parser.string(_dat)
|
126
160
|
@doc = par.parse
|
127
161
|
end
|
162
|
+
|
163
|
+
def fetch_forecast_from_noaa
|
164
|
+
_dat = if File.exists?("/tmp/forecast-#{@site}") && (File.ctime("/tmp/forecast-#{@site}") > (Time.now - (3600 * 8)))
|
165
|
+
f = open("/tmp/forecast-#{@site}")
|
166
|
+
f.read()
|
167
|
+
else
|
168
|
+
@soap ||= SOAP::WSDLDriverFactory.new('http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl').create_rpc_driver
|
169
|
+
_res = @soap.NDFDgenByDay(self.lattitude,self.longitude,self.start_time,7,'12 hourly')
|
170
|
+
f = open("/tmp/forecast-#{@site}","w")
|
171
|
+
f.write(_res.to_s)
|
172
|
+
f.close()
|
173
|
+
_res
|
174
|
+
end
|
175
|
+
par = XML::Parser.string(_dat)
|
176
|
+
@doc = par.parse
|
177
|
+
end
|
128
178
|
|
129
179
|
def cache_to_file(dat)
|
130
180
|
f = open("/tmp/weatherfile-#{@site}",'w')
|
131
181
|
f.write(dat.to_s)
|
132
182
|
f.close()
|
133
183
|
end
|
184
|
+
|
134
185
|
|
135
186
|
end
|
data/spec/noaa-weather.spec
CHANGED
@@ -57,8 +57,9 @@ describe Noaaweather do
|
|
57
57
|
it "should report the current conditions as a hash with attributes when passed true" do
|
58
58
|
@w.current_conditions(true).should_not be_nil
|
59
59
|
@w.current_conditions(true).should be_an_instance_of(Hash)
|
60
|
-
@w.current_conditions(true)[:
|
61
|
-
@w.current_conditions(true)[:
|
60
|
+
@w.current_conditions(true)[:high].should_not be_nil
|
61
|
+
@w.current_conditions(true)[:low].should_not be_nil
|
62
|
+
@w.current_conditions(true)[:conditions].should_not be_nil
|
62
63
|
end
|
63
64
|
|
64
65
|
it "should report if the data is from a cached store or not" do
|
@@ -78,4 +79,10 @@ describe Noaaweather do
|
|
78
79
|
@w.should respond_to(:fetch)
|
79
80
|
@w.fetch.should_not be_nil
|
80
81
|
end
|
82
|
+
|
83
|
+
it "should respond to forecast and return a Hash" do
|
84
|
+
@w.should respond_to(:forecast)
|
85
|
+
@w.forecast.should_not be_empty
|
86
|
+
@w.forecast.should be_an_instance_of(Hash)
|
87
|
+
end
|
81
88
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: noaa-weather
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kognate
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
M36Zgg==
|
31
31
|
-----END CERTIFICATE-----
|
32
32
|
|
33
|
-
date: 2009-03-
|
33
|
+
date: 2009-03-31 00:00:00 -04:00
|
34
34
|
default_executable:
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
metadata.gz.sig
CHANGED
Binary file
|