Skip to content

Instantly share code, notes, and snippets.

@bullfight
Forked from seanstickle/gist:554681
Created August 28, 2010 04:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bullfight/554688 to your computer and use it in GitHub Desktop.
Save bullfight/554688 to your computer and use it in GitHub Desktop.
require "rubygems"
require "net/http"
require "open-uri"
data = open("http://cdo.ncdc.noaa.gov/climatenormals/clim84/IL/IL110055.txt").map
#data = open("http://cdo.ncdc.noaa.gov/climatenormals/clim84/IL/IL112679.txt").map
metric = {}
metric[:station_coop_id] = data[4][44..49]
metric[:station_name] = data[5][44..78].strip
metric[:state] = data[5][79..80]
metric[:division] = data[5][82..83]
metric[:latitude] = data[6][44..64].split(" ")[0..2]
metric[:longitude] = data[6][44..64].split(" ")[3..5]
metric[:elevation] = data[6][66..70].strip
metric[:elements] = data[6][72..-1].strip
data.slice! 0,8
data.each_with_index do |line,i|
if data[i+1] =~ /^ DAY/
@new_measure = true
end
if line =~ /^-/ || line =~ /^ DAY/
next
end
if line =~ /^\s+$/
next
end
if @new_measure
@measure = line.strip
metric[@measure] = {}
@new_measure = false
next
end
if %w[JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC].include? line[0..2]
row = line.split(/\s+/)
metric[@measure][row[0]] = row[1..-2].map{|x| x.to_i}
end
end
p metric
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment