Skip to content

Instantly share code, notes, and snippets.

@ik5 ik5/redalarm.rb
Last active Aug 29, 2015

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

commented Jul 21, 2014

nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.