Created
May 21, 2011 20:15
-
-
Save obi-a/984859 to your computer and use it in GitHub Desktop.
check if location had an earthquake in the last 7 days (realtime) #hackdisrupt #
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'csv-mapper' | |
require 'open-uri' | |
require 'activesupport' | |
def had_earthquake(location) | |
source = "http://earthquake.usgs.gov/earthquakes/catalogs/eqs7day-M1.txt" | |
problem_regions = [] | |
count = 0 | |
FasterCSV.foreach(open(source)) do |row| | |
if row[9].index(location.titlecase) != nil | |
#CSV format: Src 0 ,Eqid 1,Version 2,Datetime 3,Lat 4,Lon 5,Magnitude 6,Depth 7,NST 8,Region 9 | |
region = {:datetime => row[3], :latitude => row[4], :longitude => row[5], :magnitude => row[6], | |
:depth => row[7], :region => row[9]} | |
#puts region.inspect | |
problem_regions[count] = region | |
count = count + 1 | |
end | |
end # end of CSV parser | |
return problem_regions #returns [] when location has no earthquakes | |
end | |
#puts problem_regions.inspect | |
puts had_earthquake('alaska').inspect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment