Skip to content

Instantly share code, notes, and snippets.

@halka
Created November 3, 2013 05:21
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 halka/7287058 to your computer and use it in GitHub Desktop.
Save halka/7287058 to your computer and use it in GitHub Desktop.
noaa.govからmetarを取ってきてim.kayac.com経由でiPhoneにプッシュ配信する例。cronで数分おきに発火させてます。
<?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