Hallo.
Anbei meine Anpassung an die API von Weather Underground. Ist zwar mit heisser Nadel gestrickt (WAF im Nacken :eek: - „Wo ist die Wetterseite geblieben?!“:rolleyes:) aber vielleicht kann es dem einen oder anderen ja als Grundlage dienen:
Bitte beachten, dass da diverse Anpassungen vorzunehmen sind. API-Key, Ortsname, Landkreis, lokale Temperatur und Luftdruck. Letzere beiden messe ich lieber selber als Sie von einem Wetterdienst zu holen.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Cache-Control" content="no-store, no-cache, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">
<link rel="stylesheet" type="text/css" href="wetterUser.css" />
</head><body>
<?php
require_once IPS_GetKernelDir()."scripts\konfigurationWetter.ips.php";
// Modifikation Wetter.com ANFANG ===========================
$key = "xxxxxxxxxxxxxxxxxxxx"; // Bei www.wunderground anfordern
$sprache = "DL"; // DL = deutsch
$land = "Germany"; // Land
$city = "Name des Ortes"; // Lässt sich mittels Funktion geolookup und Längen-/Breitengrad ermitteln. Siehe auch Dokumentation der API
$iconset = "http://icons-ak.wxug.com/i/c/h/"; // gewünschtes Icon-Set
$json_string = file_get_contents("http://api.wunderground.com/api/".$key."/forecast/lang:".$sprache."/q/".$land."/".$city.".json");
$parsed_json = json_decode($json_string);
$replace = array("Ä","Ö","Ãœ","ä","ö","ü","ß","é","è","ê","â","á","Ã","§","°");
$umlaute = array("Ä","Ö","Ü","ä","ö","ü","ß","é","è","ê","â","á","à","§","°");
$wetter['stadt'] = "Name des Ortes";
$wetter['datum'] = $parsed_json->{'forecast'}->{'simpleforecast'}->forecastday[0]->{'date'}->{'day'}.".";
$wetter['datum'] = $wetter['datum'].$parsed_json->{'forecast'}->{'simpleforecast'}->forecastday[0]->{'date'}->{'month'}.".";
$wetter['datum'] = $wetter['datum'].$parsed_json->{'forecast'}->{'simpleforecast'}->forecastday[0]->{'date'}->{'year'};
$wetter['zeit'] = $parsed_json->{'forecast'}->{'simpleforecast'}->forecastday[0]->{'date'}->{'hour'}.":";
$wetter['zeit'] = $wetter['zeit'].$parsed_json->{'forecast'}->{'simpleforecast'}->forecastday[0]->{'date'}->{'min'}.":";
//$wetter['zeit'] = $wetter['zeit'].$parsed_json->{'forecast'}->{'simpleforecast'}->forecastday[0]->{'date'}->{'sec'};
$wetter[0]['temperatur'] = GetValue(10477);
for ($i = 0; $i <= 3; $i++) {
$wetter[$i]['tag'] = $parsed_json->{'forecast'}->{'simpleforecast'}->forecastday[$i]->{'date'}->{'weekday'};
$wetter[$i]['temp_min'] = $parsed_json->{'forecast'}->{'simpleforecast'}->forecastday[$i]->{'low'}->{'celsius'};
$wetter[$i]['temp_max'] = $parsed_json->{'forecast'}->{'simpleforecast'}->forecastday[$i]->{'high'}->{'celsius'};
$wetter[$i]['hum_ave'] = $parsed_json->{'forecast'}->{'simpleforecast'}->forecastday[$i]->{'avehumidity'};
$wetter[$i]['hum_min'] = $parsed_json->{'forecast'}->{'simpleforecast'}->forecastday[$i]->{'minhumidity'};
$wetter[$i]['hum_max'] = $parsed_json->{'forecast'}->{'simpleforecast'}->forecastday[$i]->{'maxhumidity'};
$wetter[$i]['ave_wind_kmh'] = $parsed_json->{'forecast'}->{'simpleforecast'}->forecastday[$i]->{'avewind'}->{'kph'};
$wetter[$i]['ave_wind_dir'] = str_replace($replace, $umlaute, $parsed_json->{'forecast'}->{'simpleforecast'}->forecastday[$i]->{'avewind'}->{'dir'});
$wetter[$i]['max_wind_kmh'] = $parsed_json->{'forecast'}->{'simpleforecast'}->forecastday[$i]->{'maxwind'}->{'kph'};
$wetter[$i]['max_wind_dir'] = str_replace($replace, $umlaute, $parsed_json->{'forecast'}->{'simpleforecast'}->forecastday[$i]->{'maxwind'}->{'dir'});
$wetter[$i]['icon'] = $parsed_json->{'forecast'}->{'simpleforecast'}->forecastday[$i]->{'icon_url'};
$wetter[$i]['icon'] = $iconset.substr($wetter[$i]['icon'], strrpos($wetter[$i]['icon'], "/")+1);
$wetter[$i]['zustand'] = str_replace($replace, $umlaute, $parsed_json->{'forecast'}->{'simpleforecast'}->forecastday[$i]->{'conditions'});
}
// Modifikation Wetter.com ENDE ===========================
$tableAktuell = "<table>";
$tableAktuell .= "<tr><td style='width:200px;'>";
$tableAktuell .= $wetter[0]['zustand']."<br/>
";
$tableAktuell .= "Ist-Temperatur: ".$wetter[0]['temperatur']." °C<br/>
";
$tableAktuell .= "Erwartet ".$wetter[0]['temp_min']." - ".$wetter[0]['temp_max']." °C<br/>";
$tableAktuell .= "Luftfeuchte: ".$wetter[0]['hum_min']." - ".$wetter[0]['hum_max']." %"."<br/>";
$tableAktuell .= "Wind: ".$wetter[0]['ave_wind_kmh']." - ".$wetter[0]['max_wind_kmh']." Km/h"."<br/>";
$tableAktuell .= "aus ".$wetter[0]['ave_wind_dir']." - ".$wetter[0]['max_wind_dir']."."."<br/>";
$tableAktuell .= "Luftdruck: ".GetValueFormatted(46254)."<br/>";
//$tableAktuell .= "Luftdruck: ".GetValueFormatted(29351)." hPa<br/>";
$tableAktuell .= "</td>";
$tableAktuell .= "<td style='width:80px;'><img src=\"".$wetter[0]['icon']."\" alt=\"".$wetter[0]['zustand']."\"height=120 />
";
$tableAktuell .= "</td></tr></table>";
$tableTage = "<table>";
for ($i = 1; $i <= 3; $i++) {
$tableTage .= "<td style='width:220px;'>";
$tableTage .= "<b>".$wetter[$i]['tag']."</b><br/>
";
$tableTage .= $wetter[$i]['zustand']."<br/>
";
$tableTage .= "Temp. ".$wetter[$i]['temp_min']." - ".$wetter[$i]['temp_max']." °C<br/>";
$tableTage .= "Luftf. ".$wetter[$i]['hum_min']." - ".$wetter[$i]['hum_max']." %<br/>";
$tableTage .= "<img src=\"".$wetter[$i]['icon']."\" alt=\"".$wetter[$i]['zustand']."\"height=80 />
";
$tableTage .= "</td>";
}
$tableTage .= "</tr></table>";
$imgKarte = Sys_GetURLContent("http://www.dwd.de/dyn/app/ws/maps/".$warnung);
$imagePfad = IPS_GetKernelDir()."webfront/user/WetterFtpDWD/warnungen/".$warnung;
$fp = fopen($imagePfad, "wb+");
fwrite($fp, $imgKarte);
fclose($fp);
$image = imagecreatefromgif($imagePfad);
list($width, $height) = getimagesize($imagePfad);
$newWidth = $width * $factorWetterwarnung;
$newHeight = $height * $factorWetterwarnung;
$imageResized = ImageCreateTrueColor($newWidth, $newHeight);
$transparenz = ImageColorTransparent($image, imagecolorexact($image, 255, 255, 255));
for($i=0; $i<$height; $i++)
{
for($j=0; $j<$width; $j++)
{
$pos = imagecolorat($image, $j, $i);
$index = imagecolorsforindex($image, $pos);
$rgb = $index["red"] + $index["green"] + $index["blue"];
if($rgb == "0")
{
$weiss = imagecolorresolve($image, 255, 255, 255);
imagesetpixel($image, $j, $i, $weiss);
}
}
}
ImageColorTransparent($imageResized, $transparenz);
ImageCopyResampled($imageResized, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
$normal[0] = imagecolorexact($imageResized, 102, 181, 255);
$pos = array_search(imagecolorat($imageResized, $posX, $posY), $normal);
if($pos === false)
{
if(!($conn_id = ftp_connect($ftp_server)))
{
goto weiter;
}
if(!($login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass)))
{
ftp_close($conn_id);
}
if(!ftp_pasv($conn_id, true))
{
ftp_close($conn_id);
}
ftp_chdir($conn_id, "gds/specials/warnings/sms/".$warnRegion."/");
$ftp_list = ftp_nlist($conn_id, ".");
$h = date("d");
$suche = "/(H[\w]{1}{$warnRegion}[\d]{2})_{$landkreis}[\w]{1}_({$h}[\d]{4})/";
foreach($ftp_list as $lk => $v)
{
preg_match_all($suche, $v, $s, PREG_SET_ORDER);
foreach($s as $sms)
{
$sim[] = $sms;
}
}
if(!isset($sim))
{
SetValue(24108, "Es sind keine Warnmeldungen für den Landkreis vorhanden!");
}
else
{
$smsMeldung = array_pop($sim);
$letztesmsMeldung = array_shift($smsMeldung);
$smsMeldung = IPS_GetKernelDir()."webfront/user/WetterFtpDWD/warnungen/smsWarnmeldung.txt";
$handleSMS = @fopen($smsMeldung, 'wb+');
if(!ftp_fget($conn_id, $handleSMS, $letztesmsMeldung, FTP_ASCII))
{
//Meldung
}
fclose($handleSMS);
$smsWarnmeldung = file_get_contents("../WetterFtpDWD/warnungen/smsWarnmeldung.txt");
SetValue(24108, $smsWarnmeldung);
}
ftp_close($conn_id);
}
//
//else
//{
// $color = imagecolorallocate($imageResized, 255, 0, 0);
// ImageRectangle($imageResized, $posX+1, $posY+1, $posX, $posY, $color);
//}
weiter:
imagegif($imageResized, $imagePfad);
imagedestroy($image);
imagedestroy($imageResized);
$berichtHeute = file_get_contents("../WetterFtpDWD/berichte/berichtHeute.txt");
$berichtHeute = preg_replace('/\b[A-Z]{1}+[a-z]{4,}\b.*([:].*)/', "", $berichtHeute);
//$berichtHeute = preg_replace('/Letzte Aktualisierung: ([\d]{2}.[\d]{2}.[\d]{4}, [\d]{2}.[\d]{2} Uhr)/', "", $berichtHeute);
$berichtMorgen = file_get_contents("../WetterFtpDWD/berichte/berichtMorgen.txt");
$berichtMorgen = preg_replace('/\b[A-Z]{1}+[a-z]{4,}\b.*([:].*)/', "", $berichtMorgen);
$berichtUebermorgen = file_get_contents("../WetterFtpDWD/berichte/berichtUebermorgen.txt");
$berichtUebermorgen = preg_replace('/\b[A-Z]{1}+[a-z]{4,}\b.*([:].*)/', "", $berichtUebermorgen);
$berichtTag4 = file_get_contents("../WetterFtpDWD/berichte/berichtTag4.txt");
$berichtTag4 = preg_replace('/\b[A-Z]{1}+[a-z]{4,}\b.*([:].*)/', "", $berichtTag4);
$berichtGesamt = $berichtHeute;
if($berichtanzahl == 2) $berichtGesamt = $berichtHeute . $berichtMorgen;
if($berichtanzahl == 3) $berichtGesamt = $berichtHeute . $berichtMorgen . $berichtUebermorgen;
if($berichtanzahl == 4) $berichtGesamt = $berichtHeute . $berichtMorgen . $berichtUebermorgen . $berichtTag4;
if($berichtGesamt == "")
{
$berichtGesamt = "Der Wetterbericht steht momentan nicht zur Verfügung!";
}
?>
<div id="containerTopLeft">
<div class="pos"><?php echo $ort;?></div>
<div class="containerBorderAktuell">
<div class="containerTableAktuell"><?php echo $tableAktuell;?></div>
</div>
</div>
<div id="containerTopRight">
<div class="pos">Vorhersage für die nächsten 3 Tage</div>
<div class="containerBorderTage">
<div class="containerTableTage"><?php echo $tableTage;?></div>
</div>
</div>
<div id="containerBottomLeft">
<div class="pos"><?php echo $ueberschriftKarte;?></div>
<div class="containerWarnung">
<div class="containerGif"><img src='/user/WetterFtpDWD/warnungen/<?php echo $warnung;?>' border="0" alt="karte" usemap="#karte">
<div class="linkGif"><map name="karte">
<area shape="poly" coords="120,209,124,206,128,205,131,208,137,204,138,207,136,209,135,222,130,221,127,226,123,226,127,222,119,219,120,210"
href="Warnmeldung.php" alt="Dein Landkreis" title="Dein Landkreis"></map>
</div>
<div class="containerTextWarnung"><img src='/user/WetterFtpDWD/warnungen/containerTextWarnungen.png'></div>
</div>
</div>
</div>
<div id="containerBottomRight">
<div class="pos">Wetterbericht</div>
<div class="containerBericht">
<div class="berichtText"><?php echo $berichtGesamt;?></div>
</div>
</div>
<?php require "barBottom.php"; ?>
</body></html>
Nachtrag - es geht hier um die WetterIndex.php.