Umstellung Yahoo Wetter API
Die Wetteranzeige via Yahoo funktioniert plötzlich nicht mehr.
Die neue API gibt kein XML mehr zurück, sondern ein JSON.
Laut Yahoo soll man angeblich nun einen Account anlegen.
Mein Sohn hat herausgefunden, wie man den Aufruf ändern muss:
[codesyntax lang=”php”]
$BASE_URL = "http://query.yahooapis.com/v1/public/yql"; $yql_query = "select * from weather.forecast where woeid=706249"; $yql_query_url = $BASE_URL . "?q=" . urlencode($yql_query) . "&format=json"; // http://query.yahooapis.com/v1/public/yql?q=select wind from weather.forecast where woeid=706249&format=json // {"query":{"count":1,"created":"2016-03-27T15:05:43Z","lang":"de-DE","results":{"channel":{"wind":{"chill":"45","direction":"220","speed":"22"}}}}} $json = file_get_contents($yql_query_url); //var_dump($json); //Convert JSON to PHP object $phpObj = json_decode($json); // var_dump($phpObj); if($json != ""){ // $xml = new SimpleXMLElement($con); $xml = $phpObj; //echo "hi<br><br>"; //$forecast = $xml->channel->item->children('yweather', true)->forecast; $forecast = $xml->query->results->channel->item->forecast; $heute = $xml->query->results->channel->item->condition;
[/codesyntax]
komplettes Script:
[codesyntax lang=”php”]
<?php // $curdir = getcwd(); $path = 'plugins/weather/color'; // $path = 'plugins/weather/vcloud'; $tage = array("So", "Mo", "Di", "Mi", "Do", "Fr", "Sa", "So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"); // <img src="/var/www/htPlugin/weather/color/11.png"> // $con = file_get_contents('http://weather.yahooapis.com/forecastrss?w=xxxxxxxxx&u=c'); // Wiehl 706249 $BASE_URL = "http://query.yahooapis.com/v1/public/yql"; $yql_query = "select * from weather.forecast where woeid=706249"; $yql_query_url = $BASE_URL . "?q=" . urlencode($yql_query) . "&format=json"; // http://query.yahooapis.com/v1/public/yql?q=select wind from weather.forecast where woeid=706249&format=json // {"query":{"count":1,"created":"2016-03-27T15:05:43Z","lang":"de-DE","results":{"channel":{"wind":{"chill":"45","direction":"220","speed":"22"}}}}} $json = file_get_contents($yql_query_url); //var_dump($json); //Convert JSON to PHP object $phpObj = json_decode($json); // var_dump($phpObj); if($json != ""){ // $xml = new SimpleXMLElement($con); $xml = $phpObj; //echo "hi<br><br>"; //$forecast = $xml->channel->item->children('yweather', true)->forecast; $forecast = $xml->query->results->channel->item->forecast; $heute = $xml->query->results->channel->item->condition; $morgen = $forecast[0]; $tag3 = $forecast[1]; $tag4 = $forecast[2]; $tag5 = $forecast[3]; echo '<img src='.$path.'/'.$heute->code.'.png>'; echo "<span class='temp3'>".fToC($heute->temp)." °C </span>"; // <span class='degc3'> / ".$heute->low." °C</span> // pic heute // Tag - img - tempHi - temp Lo echo '<br><table width="80%">'; $tag = date("w")+1; echo ' <colgroup> <col width="10"> <col width="40"> <col width="10"> <col width="10"> </colgroup> <tr> <td>'.$tage[$tag].'</td> <td><img src='.$path.'/'.$morgen->code.'.png style="width:50%"></td> <td class=underline><h2> '.fToC($morgen->high).' °C </h2></td> <td class=underline><h4> '.fToC($morgen->low).' °C </h4></td> </tr> '; $tag = date("w")+2; echo ' <tr> <td>'.$tage[$tag].'</td> <td><img src='.$path.'/'.$tag3->code.'.png style="width:50%"></td> <td class=underline><h2> '.fToC($tag3->high).' °C </h2></td> <td class=underline><h4> '.fToC($tag3->low).' °C </h4></td> </tr> '; $tag = date("w")+3; echo ' <tr> <td>'.$tage[$tag].'</td> <td><img src='.$path.'/'.$tag4->code.'.png style="width:50%"></td> <td class=underline><h2> '.fToC($tag4->high).' °C </h2></td> <td class=underline><h4> '.fToC($tag4->low).' °C </h4></td> </tr> '; echo '</table></div>'; } else{ echo "Unable to load Web Weather!"; } function fToC($i){ return round(($i-32)/1.8 , 1); } ?>
[/codesyntax]