Skip to content

Instantly share code, notes, and snippets.

@thbounzer
Created May 21, 2012 15:18
Show Gist options
  • Save thbounzer/2762876 to your computer and use it in GitHub Desktop.
Save thbounzer/2762876 to your computer and use it in GitHub Desktop.
This is a ruby quick and dirty Italy earthquake whistle. It gets periodically the last tweet from INGVterremoti feed and it requires rubygems and twitter gem installed. Also requires beep package installed on the host machine. Beep frequency depends on ma
require "rubygems"
require "twitter"
tweet_f = Twitter.user_timeline("INGVterremoti").first.text
elements = tweet_f.split(/Ml:(\d.\d) (\d{4}-\d{2}-\d{2} \d{1,2}:\d{1,2}:\d{1,2}) UTC Lat=(\d{1,2}.\d{1,2}) Lon=(\d{1,2}.\d{1,2}) Prof=(\d{1,3}.\d{1,3})Km Prov=(\D*)/)
f_tstamp = elements[2]
while(true)
sleep(60*5)
tweet_s = Twitter.user_timeline("INGVterremoti").first.text
elements = tweet_s.split(/Ml:(\d.\d) (\d{4}-\d{2}-\d{2} \d{1,2}:\d{1,2}:\d{1,2}) UTC Lat=(\d{1,2}.\d{1,2}) Lon=(\d{1,2}.\d{1,2}) Prof=(\d{1,3}.\d{1,3})Km Prov=(\D*)/)
s_tstamp = elements[2]
puts ">>> #{tweet_s} tstamp: #{s_tstamp} <<<"
if(f_tstamp != s_tstamp)
puts "!!! New eartquake: #{tweet_s} !!!"
freq = elements[1].to_f*1000
Kernel.system "beep -f #{freq} -l 300"
f_tstamp = s_tstamp
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment