outoftime-noaa 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +1 -0
- data/Manifest +24 -0
- data/README +77 -0
- data/Rakefile +30 -0
- data/bin/noaa-update-stations +12 -0
- data/data/stations.yml +12091 -0
- data/lib/noaa/current_conditions.rb +141 -0
- data/lib/noaa/forecast.rb +94 -0
- data/lib/noaa/forecast_day.rb +30 -0
- data/lib/noaa/http_service.rb +19 -0
- data/lib/noaa/station.rb +111 -0
- data/lib/noaa/station_writer.rb +26 -0
- data/lib/noaa.rb +61 -0
- data/noaa.gemspec +54 -0
- data/test/data/4-day.xml +116 -0
- data/test/data/KVAY.xml +52 -0
- data/test/data/stations-abridged.xml +44 -0
- data/test/data/stations.xml +22177 -0
- data/test/data/stations.yml +12091 -0
- data/test/test_current_conditions.rb +129 -0
- data/test/test_forecast.rb +57 -0
- data/test/test_helper.rb +16 -0
- data/test/test_http_service.rb +57 -0
- data/test/test_station.rb +65 -0
- data/test/test_station_writer.rb +49 -0
- metadata +145 -0
data/CHANGELOG
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
v0.1.0. Initial release
|
data/Manifest
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
lib/noaa/forecast.rb
|
2
|
+
lib/noaa/http_service.rb
|
3
|
+
lib/noaa/current_conditions.rb
|
4
|
+
lib/noaa/station_writer.rb
|
5
|
+
lib/noaa/station.rb
|
6
|
+
lib/noaa/forecast_day.rb
|
7
|
+
lib/noaa.rb
|
8
|
+
Rakefile
|
9
|
+
Manifest
|
10
|
+
data/stations.yml
|
11
|
+
bin/noaa-update-stations
|
12
|
+
CHANGELOG
|
13
|
+
test/test_station_writer.rb
|
14
|
+
test/test_forecast.rb
|
15
|
+
test/data/stations.xml
|
16
|
+
test/data/stations-abridged.xml
|
17
|
+
test/data/stations.yml
|
18
|
+
test/data/KVAY.xml
|
19
|
+
test/data/4-day.xml
|
20
|
+
test/test_helper.rb
|
21
|
+
test/test_station.rb
|
22
|
+
test/test_http_service.rb
|
23
|
+
test/test_current_conditions.rb
|
24
|
+
README
|
data/README
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
= noaa
|
2
|
+
|
3
|
+
* http://github.com/outoftime/noaa
|
4
|
+
|
5
|
+
== Description:
|
6
|
+
|
7
|
+
noaa is a library that provides an API for the National Oceanic and Atmospheric Association's weather
|
8
|
+
data feeds. It currently provides access to two types of data: current conditions (through NOAA::CurrentConditions) and
|
9
|
+
daily forecasts (through NOAA::Forecast).
|
10
|
+
|
11
|
+
== Features:
|
12
|
+
|
13
|
+
- Find both current conditions and daily forecasts using lat/lng.
|
14
|
+
- Access all relevant data returned by the NOAA using a simple and intuitive API
|
15
|
+
|
16
|
+
== Requirements:
|
17
|
+
|
18
|
+
- libxml-ruby >= 0.9.7 (if there is demand, I could look into allowing REXML as a fallback - shoot me an email)
|
19
|
+
- andre-geokit >= 1.2.0
|
20
|
+
|
21
|
+
== Installation:
|
22
|
+
|
23
|
+
sudo gem sources --add http://gems.github.com (only if you haven't done this before)
|
24
|
+
sudo gem install outoftime-noaa
|
25
|
+
noaa-update-stations
|
26
|
+
|
27
|
+
== Usage:
|
28
|
+
|
29
|
+
# Get current conditions
|
30
|
+
conditions = NOAA.current_conditions(lat, lng)
|
31
|
+
puts "The temperature is currently #{conditions.temperature} degrees, with #{conditions.weather_description.downcase} conditions."
|
32
|
+
|
33
|
+
# Get closest weather station, then get current conditions
|
34
|
+
# See discussion in documentation of NOAA.current_conditions
|
35
|
+
# for why this is a good idea
|
36
|
+
station_id = NOAA::Station.closest_to(lat, lng).id
|
37
|
+
# persist the station id wherever...
|
38
|
+
conditions = NOAA.current_conditions_for_station(station_id)
|
39
|
+
|
40
|
+
# Get four-day forecast
|
41
|
+
forecast = NOAA.forecast(4, lat, lng) # This method should not be called more than once an hour for a given lat/lng
|
42
|
+
['today', 'tomorrow', (Date.today + 2).to_s, (Date.today + 3).to_s].each_with_index do |date, i|
|
43
|
+
puts "The high for #{date} will be #{forecast[i].high}"
|
44
|
+
end
|
45
|
+
|
46
|
+
See the API documentation for further discussion.
|
47
|
+
|
48
|
+
== Contact:
|
49
|
+
|
50
|
+
Mat Brown (mat@patch.com)
|
51
|
+
|
52
|
+
I'm always open to feature requests, bugs, and patches.
|
53
|
+
|
54
|
+
== License:
|
55
|
+
|
56
|
+
(The MIT License)
|
57
|
+
|
58
|
+
Copyright (c) 2008 Mat Brown
|
59
|
+
|
60
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
61
|
+
a copy of this software and associated documentation files (the
|
62
|
+
'Software'), to deal in the Software without restriction, including
|
63
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
64
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
65
|
+
permit persons to whom the Software is furnished to do so, subject to
|
66
|
+
the following conditions:
|
67
|
+
|
68
|
+
The above copyright notice and this permission notice shall be
|
69
|
+
included in all copies or substantial portions of the Software.
|
70
|
+
|
71
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
72
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
73
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
74
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
75
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
76
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
77
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
ENV['RUBYOPT'] = '-W1'
|
4
|
+
|
5
|
+
require 'ftools'
|
6
|
+
require 'rubygems'
|
7
|
+
gem 'echoe', '~>3.0'
|
8
|
+
require 'echoe'
|
9
|
+
require './lib/noaa.rb'
|
10
|
+
|
11
|
+
Echoe.new('noaa', NOAA::VERSION) do |p|
|
12
|
+
p.name = 'noaa'
|
13
|
+
p.author = 'Mat Brown'
|
14
|
+
p.description = 'Ruby API for National Oceanic and Atmospheric Administration weather data'
|
15
|
+
p.email = 'mat@patch.com'
|
16
|
+
p.url = 'http://github.com/outoftime/noaa'
|
17
|
+
p.install_message = "Be sure to update the weather station list:\n\n\tnoaa-update-stations\n\nThis can be run at any time to update the stations, but you must run it once to initially populate the station list."
|
18
|
+
p.runtime_dependencies = [Gem::Dependency.new('libxml-ruby', '>= 0.9.7'),
|
19
|
+
Gem::Dependency.new('andre-geokit', '>= 1.2.0')]
|
20
|
+
p.development_dependencies = [Gem::Dependency.new('jeremymcanally-context', '>= 0.0.6'),
|
21
|
+
Gem::Dependency.new('jeremymcanally-matchy', '>= 0.0.1'),
|
22
|
+
Gem::Dependency.new('ruby-debug', '~> 0.10')]
|
23
|
+
end
|
24
|
+
|
25
|
+
desc 'Create gemspec and copy it into project root'
|
26
|
+
task :gemspec => :package do
|
27
|
+
File.copy(File.join(File.dirname(__FILE__), 'pkg', "noaa-#{NOAA::VERSION}", 'noaa.gemspec'), File.join(File.dirname(__FILE__), 'noaa.gemspec'))
|
28
|
+
end
|
29
|
+
|
30
|
+
# vim: syntax=Ruby
|
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'noaa')
|
4
|
+
|
5
|
+
begin
|
6
|
+
file = File.open(File.join(File.dirname(__FILE__), '..', 'data', 'stations.yml'), 'w')
|
7
|
+
puts 'Downloading station list from NOAA...'
|
8
|
+
doc = NOAA::HttpService.new.get_station_list
|
9
|
+
puts 'Converting station list to YAML...'
|
10
|
+
NOAA::StationWriter.new(doc).write(file)
|
11
|
+
puts "Done."
|
12
|
+
end
|