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]

東京電力はじめ、各電力会社の情報から、電力使用率を割り出す方法。

https://elecwarn.kuropen.org/

http://developer.yahoo.co.jp/webapi/shinsai/setsuden/v1/latestpowerusage.html

などから、沖縄電力を除く、電力会社9社の電力使用率が割り出せます。

Yahoo! デベロッパーネットワークの方は、会員登録が必要になります。無料で登録が出来ます。

しかし、Yahoo! デベロッパーネットワークを使わなくても、Electricity Warningを使うことによって、沖縄電力を除く、電力会社9社のデーターを入手できます。

ここでは、ヒントとしまして、私が作った、PHPのfunctionを載せておきます。

crayonでまとめると、見にくいので、ご自分で研究してみて下さいね!

上の方の東京電力の方のプログラムは、ミソは、@simplexml_load_file(); を使っているところがミソです。

そして、下の方の中国電力のプログラムは、json_decode(); を使っているところがミソなんですね。

※皆さんのプログラムの中に、当プログラムを組み込んで、ご自由に改変して下さい。その際に、私への連絡は不要です。

[crayon]
function tokyo_denryoku() {
global $APPID_YAHOO;
$req = “http://setsuden.yahooapis.jp/v1/Setsuden/latestPowerUsage?appid=”.$APPID_YAHOO.”&area=tokyo&latest=1″;

$xml = NULL;
$kurikaeshi = 10;
$sleeptime = 60;

for ($count = 0; $count < $kurikaeshi; $count++){ $xml = @simplexml_load_file($req); if ($xml) { // var_dump($xml); $tokyo_den["usage"] = (int)(($xml->Usage) / 10000);
$tokyo_den[“capacity”] = (int)(($xml->Capacity) / 10000);
$tokyo_den[“den_per”] = round((float)($tokyo_den[“usage”] / $tokyo_den[“capacity”]) * 100,1);
return($tokyo_den);
} else {
sleep($sleeptime);
}
}
return(NULL);
}

function chugoku_denryoku() {
$xml = NULL;
$kurikaeshi = 10;
$sleeptime = 60;

for ($count = 0; $count < $kurikaeshi; $count++){ $json = @file_get_contents("https://elecwarn.kuropen.org/json"); if ($json) { $obj = json_decode($json); for ($place = 0;$place < 9;$place++){ if ($obj[$place]->company == “chugoku”){
$chugoku = array();
$chugoku[“usage”] = $obj[$place]->consume;
$chugoku[“capacity”] = $obj[$place]->capacity;
$chugoku[“den_per”] = round((float)($chugoku[“usage”] / $chugoku[“capacity”]) * 100,1);
return($chugoku);
}
}
return(NULL);
} else {
sleep($sleeptime);
}
}
return(NULL);
}

[/crayon]