Skip to content

Instantly share code, notes, and snippets.

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 obi-a/984859 to your computer and use it in GitHub Desktop.
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 #
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