Last active
August 29, 2015 14:00
-
-
Save yoggy/11207061 to your computer and use it in GitHub Desktop.
find_af1.rb - ものすごく雑なエアフォースワンが飛んでるかどうか探すスクリプト。参考URL→ http://theaviationist.com/2011/11/24/af1-adsb/
This file contains hidden or 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/ruby | |
require 'open-uri' | |
require 'json' | |
require 'logger' | |
$url = "http://db8.flightradar24.com/zones/japan_all.js" | |
$log = Logger.new(STDOUT) | |
def is_found_af1 | |
begin | |
# jsonp -> json | |
json_str = open($url).read.scan(/^pd_callback\((.*)\);$/)[0][0] | |
# parse json | |
json = JSON.parse(json_str) | |
# search | |
json.each {|k, v| | |
s = v.to_s | |
if s =~ /AF1/ | |
$log.debug(s) | |
return true | |
end | |
} | |
rescue Exception => e | |
$log.error(e.to_s) | |
end | |
return false | |
end | |
loop do | |
if is_found_af1() | |
$log.info("FOUND!") | |
else | |
$log.info("NOTFOUND") | |
end | |
STDOUT.flush | |
sleep 60 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment