Skip to content

Instantly share code, notes, and snippets.

@ik5
Last active August 29, 2015 14:04
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 ik5/4021fb88016278abee6a to your computer and use it in GitHub Desktop.
Save ik5/4021fb88016278abee6a to your computer and use it in GitHub Desktop.
log alarms of rocket attacks on Israel using Ruby
#!/usr/bin/env ruby
require 'open-uri'
require 'json'
PKR_URL = 'http://www.oref.org.il/WarningMessages/alerts.json'
def to_json
data = open(PKR_URL).read.force_encoding('utf-16').encode('utf-8')
JSON.parse(data)
end
def to_log(&block)
log = open('alarm.log', 'a+')
yield log
log.close
end
job = fork do
while true do
json = to_json
unless json['data'].empty?
json['data'].each do |idx|
idx =~ /^([\p{hebrew}\s]+)(\d+)$/
to_log do |log|
log.puts "[#{Time.now.strftime('%D %T')} ] ישוב: #{$1} קוד: #{$2}"
end
end
end
sleep 1
end
end
Process.detach(job)
@guss77
Copy link

guss77 commented Jul 21, 2014

nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment