Created
November 3, 2013 05:21
-
-
Save halka/7287058 to your computer and use it in GitHub Desktop.
noaa.govからmetarを取ってきてim.kayac.com経由でiPhoneにプッシュ配信する例。cronで数分おきに発火させてます。
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
<?php | |
//noaaからmetarを取得する | |
function push_metar($airport,$username){ | |
$airport=strtoupper($airport); | |
$old_filename="metars/${airport}.old"; | |
$metar=file_get_contents("http://weather.noaa.gov/pub/data/observations/metar/stations/${airport}.TXT"); | |
$old_metar=@file_get_contents($old_filename); | |
if(strcmp($metar,$old_metar)!=0){ | |
file_put_contents($old_filename, $metar); | |
$data=array("message"=>$metar); | |
$data = http_build_query($data, "", "&"); | |
$header = array( | |
"Content-Type: application/x-www-form-urlencoded", | |
"Content-Length: ".strlen($data) | |
); | |
$context = array( | |
"http" => array( | |
"method" => "POST", | |
"header" => implode("\r\n", $header), | |
"content" => $data | |
) | |
); | |
$url = "http://im.kayac.com/api/post/${username}"; | |
return file_get_contents($url, false, stream_context_create($context)); | |
}else{ | |
$result=json_encode(array("id"=>"","error"=>"duplicate","result"=>"not posted")); | |
return $result; | |
} | |
} | |
echo push_metar(ICAO,USERNAME); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment