openweathermapや、wundergroundから、天気の情報を入手するfunction。
かなり、重要な内容を載せているハズなんです(笑)。
これが、私の作った、PHPのfunctionです。
色々と私はfunctionを組んだのですが、それらを全部載せると、githubのようになってしまうので、
一部だけです。
皆さんにとっても、全部解答を知ってしまうと、プログラミングがつまらないですよね?
皆さんのご健闘をお祈りします。
※皆さんのプログラムの中に、当プログラムを組み込んで、ご自由に改変して下さい。その際に、私への連絡は不要です。
[crayon]
function openweathermap(){
global $LAT,$LON,$APPID_OWM;
$xml = NULL;
$kurikaeshi = 10;
$sleeptime = 60;
for ($count=0; $count < $kurikaeshi; $count++){
$req1 = "http://api.openweathermap.org/data/2.5/weather?lat=".$LAT."&lon=".$LON."&mode=xml&appid=".$APPID_OWM;
$xml = @simplexml_load_file($req1);
if ($xml) {
// var_dump($xml);
$owm = array();
$owm["place"] = ($xml->city->attributes()->name);
$owm[“temp_now”] = round((float)($xml->temperature->attributes()->value) – 273.15,1);
$owm[“humidity_now”] = ($xml->humidity->attributes()->value);
$owm[“clouds_value”] = ($xml->clouds->attributes()->value);
$owm[“w_time”] = ($xml->lastupdate->attributes()->value);
$pos = strpos($owm[“w_time”],”T”);
$owm[“w_time_h”] = mb_strcut($owm[“w_time”],$pos + 1,2);
$owm[“w_time_m”] = mb_strcut($owm[“w_time”],$pos + 4,2);
$owm[“description”] = _ryusWheatherDescription((int)($xml->weather->attributes()->number));
return($owm);
} else {
sleep($sleeptime);
}
}
return(NULL);
}
function wunderground() {
global $LAT,$LON,$APPID_WG;
$xml = NULL;
$kurikaeshi = 10;
$sleeptime = 60;
for ($count=0; $count < $kurikaeshi; $count++){
$req2 = "http://api.wunderground.com/api/".$APPID_WG."/conditions/q/".$LAT.",".$LON.".xml";
$xml = @simplexml_load_file($req2);
if ($xml) {
// var_dump($xml);
$wg = array();
$wg["city"] = ($xml->current_observation->display_location->city);
$wg[“temp_now2”] = round((5 / 9) * (($xml->current_observation->temp_f) – 32),1);
$wg[“humidity_now2”] = str_replace(“%”,”%”,($xml->current_observation->relative_humidity));
$wg[“windspeed_now2”]= round((float)($xml->current_observation->wind_mph) / 2.24,1) ;
$wg[“pressure_now2”] = round((float)($xml->current_observation->pressure_in) * 33.8639,1);
$wg[“kazamuki2”] = _ryusWehatherWindDigree($xml->current_observation->wind_degrees);
return($wg);
} else {
sleep($sleeptime);
}
}
return(NULL);
}
[/crayon]