current_metar 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT_LICENSE +21 -0
- data/README +13 -0
- data/lib/current_metar/metar.rb +44 -0
- data/lib/current_metar/request.rb +14 -0
- data/lib/current_metar.rb +4 -0
- metadata +84 -0
data/MIT_LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2010 Nathan Humbert
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Query current metar data from the ADDS Experimental data server.
|
2
|
+
|
3
|
+
Currently returns a subset of the metar data.
|
4
|
+
Temperature (converted to Fahrenheit)
|
5
|
+
Wind direction
|
6
|
+
Wind speed
|
7
|
+
Wind gust speed
|
8
|
+
Visibility
|
9
|
+
|
10
|
+
|
11
|
+
License: MIT
|
12
|
+
|
13
|
+
Originally created to support weather data on www.checkthesock.com
|
@@ -0,0 +1,44 @@
|
|
1
|
+
class CurrentMetar::Metar
|
2
|
+
require 'rexml/document'
|
3
|
+
attr_accessor :wind_speed, :wind_direction, :wind_gust_speed, :observation_time, :visibility, :temperature, :available
|
4
|
+
attr_reader :icao
|
5
|
+
|
6
|
+
METAR_ATTRIBUTE_MAPPING = {
|
7
|
+
:wind_speed => "wind_speed_kt",
|
8
|
+
:wind_direction => "wind_dir_degrees",
|
9
|
+
:wind_gust_speed => "wind_gust_kt",
|
10
|
+
:visibility => "visibility_statute_mi"
|
11
|
+
}
|
12
|
+
|
13
|
+
def initialize(icao)
|
14
|
+
@icao = icao
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.get_metar(icao)
|
18
|
+
|
19
|
+
metar = CurrentMetar::Metar.new(icao)
|
20
|
+
begin
|
21
|
+
metar_response_body = REXML::Document.new(CurrentMetar::Request.query_adds(metar.icao))
|
22
|
+
metar_response_body.root.elements.each("data/METAR") do |metar_xml|
|
23
|
+
unless metar_xml.elements['temp_c'].nil?
|
24
|
+
metar.temperature = (9/5.0 * metar_xml.elements['temp_c'].text.to_i + 32).round
|
25
|
+
end
|
26
|
+
metar.parse_standard_attributes(metar_xml)
|
27
|
+
end
|
28
|
+
metar.available = true
|
29
|
+
rescue
|
30
|
+
metar.available = false
|
31
|
+
ensure
|
32
|
+
return metar
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def parse_standard_attributes(metar_xml)
|
37
|
+
METAR_ATTRIBUTE_MAPPING.each do |key, value|
|
38
|
+
unless metar_xml.elements[value].nil?
|
39
|
+
self.send( "#{key}=", metar_xml.elements[value].text)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class CurrentMetar::Request
|
2
|
+
require 'net/http'
|
3
|
+
require 'uri'
|
4
|
+
require 'rexml/document'
|
5
|
+
|
6
|
+
def self.query_adds(icao)
|
7
|
+
url = URI.parse("http://weather.aero/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=xml&hoursBeforeNow=3&mostRecent=true&stationString=#{icao}")
|
8
|
+
request = Net::HTTP.start(url.host, url.port) do |http|
|
9
|
+
http.get(url.path + "?" + url.query)
|
10
|
+
end
|
11
|
+
return request.body
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: current_metar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 9
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: "0.1"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Nathan Humbert
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-12-29 00:00:00 -08:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: fakeweb
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
description: current_metar queries the ADDS Experimental server to pull back current weather data for a specific reporting station
|
35
|
+
email:
|
36
|
+
- nathan.humbert@gmail.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files: []
|
42
|
+
|
43
|
+
files:
|
44
|
+
- README
|
45
|
+
- MIT_LICENSE
|
46
|
+
- lib/current_metar/metar.rb
|
47
|
+
- lib/current_metar/request.rb
|
48
|
+
- lib/current_metar.rb
|
49
|
+
has_rdoc: true
|
50
|
+
homepage: https://github.com/nathanhumbert/current_metar
|
51
|
+
licenses:
|
52
|
+
- MIT
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
hash: 3
|
64
|
+
segments:
|
65
|
+
- 0
|
66
|
+
version: "0"
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: 3
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
version: "0"
|
76
|
+
requirements: []
|
77
|
+
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 1.3.7
|
80
|
+
signing_key:
|
81
|
+
specification_version: 3
|
82
|
+
summary: Query current metar data from the ADDS Experimental data server.
|
83
|
+
test_files: []
|
84
|
+
|