metar-parser 0.1.5 → 0.1.6
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 +9 -0
- data/bin/download_raw.rb +0 -2
- data/lib/metar.rb +1 -1
- data/lib/metar/raw.rb +34 -10
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -20,6 +20,15 @@ The information comes from the National Oceanic and Atmospheric Association's ra
|
|
20
20
|
* http://weather.cod.edu/notes/metar.html
|
21
21
|
* http://www.met.tamu.edu/class/METAR/metar-pg3.html - incomplete
|
22
22
|
|
23
|
+
= Sources
|
24
|
+
|
25
|
+
* Single Files
|
26
|
+
** ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/[CCCC].TXT - plain text, time 3.1s
|
27
|
+
** http://weather.noaa.gov/cgi-bin/mgetmetar.pl?cccc=LIRQ - embedded in HTML, time 0.3s
|
28
|
+
* Cycle Files
|
29
|
+
** http://weather.noaa.gov/weather/metar.shtml
|
30
|
+
** ftp://tgftp.nws.noaa.gov/data/observations/metar/cycles/[NN]Z.TXT
|
31
|
+
|
23
32
|
= Other software
|
24
33
|
|
25
34
|
Other Ruby libraries offering METAR parsing:
|
data/bin/download_raw.rb
CHANGED
data/lib/metar.rb
CHANGED
data/lib/metar/raw.rb
CHANGED
@@ -9,22 +9,46 @@ module Metar
|
|
9
9
|
|
10
10
|
@connection = nil
|
11
11
|
|
12
|
-
def cache_connection
|
13
|
-
@connection = connection
|
14
|
-
end
|
15
|
-
|
16
12
|
def connection
|
17
13
|
return @connection if @connection
|
18
|
-
connection = Net::FTP.new('tgftp.nws.noaa.gov')
|
19
|
-
connection.login
|
20
|
-
connection.
|
21
|
-
connection
|
22
|
-
connection
|
14
|
+
@connection = Net::FTP.new('tgftp.nws.noaa.gov')
|
15
|
+
@connection.login
|
16
|
+
@connection.passive = true
|
17
|
+
@connection
|
23
18
|
end
|
24
19
|
|
25
20
|
def fetch(cccc)
|
21
|
+
fetch_file("#{ cccc }.TXT", '/data/observations/metar/stations')
|
22
|
+
end
|
23
|
+
|
24
|
+
# Downloads the latest cycle file (http://weather.noaa.gov/weather/metar.shtml#files)
|
25
|
+
# The files contain a lot (circa 80%) of duplicates
|
26
|
+
# Returns a hash { '[CCCC code]' => 2 line METAR report }
|
27
|
+
# This function takes 10s of seconds to download
|
28
|
+
# N.B.: There is a 10m period each day when each file is not present (the 10m before data is collected)
|
29
|
+
def hourly(hour = current_cycle_hour)
|
30
|
+
cycle_file_name = "%02uZ.TXT" % hour
|
31
|
+
cycle_file = fetch_file(cycle_file_name, '/data/observations/metar/cycles')
|
32
|
+
cycle_file.each_line("\n\n").reduce({}) do |memo, metar|
|
33
|
+
metar =~ /\n([A-Z]...)\s/
|
34
|
+
cccc = $1
|
35
|
+
memo[cccc] = metar
|
36
|
+
memo
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# For logic, see http://weather.noaa.gov/weather/metar.shtml - A Discussion of METAR Cycles
|
41
|
+
def current_cycle_hour
|
42
|
+
time = Time.now.gmtime
|
43
|
+
time.min > 44 ? time.hour : time.hour - 1
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def fetch_file(file, directory = nil)
|
49
|
+
connection.chdir(directory) if directory
|
26
50
|
s = ''
|
27
|
-
connection.retrbinary("RETR #{
|
51
|
+
connection.retrbinary("RETR #{ file }", 1024) do |chunk|
|
28
52
|
s << chunk
|
29
53
|
end
|
30
54
|
s
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 6
|
9
|
+
version: 0.1.6
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Joe Yates
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-03-
|
17
|
+
date: 2010-03-19 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|