Last active
August 29, 2015 14:04
-
-
Save ik5/4021fb88016278abee6a to your computer and use it in GitHub Desktop.
log alarms of rocket attacks on Israel using Ruby
This file contains 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
#!/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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice