Page 1 of 1

warningsDE

Posted: Sat Jan 29, 2022 7:28 am
by Piddy
Hallo zusammen,

ich habe folgendes Problem, ich bekomme nicht für mein Bundesland die Wetterwarnungen, irgendetwas habe ich übersehen oder falsch gemacht, könnte mit jemand für sein Bundesland sein Script zur Verfügung stellen, dann könnte ich mir das abkupfern.

Vielen Dank und bleibt gesund!

Re: warningsDE

Posted: Sat Jan 29, 2022 11:05 am
by davidefa
What your state short name ( as setup in the block ) and full name?

Re: warningsDE

Posted: Sat Jan 29, 2022 11:14 am
by Piddy
Short name SHH Schleswig-Holstein, Kreis Plön, Kreis Ostholstein

Re: warningsDE

Posted: Sat Jan 29, 2022 11:18 am
by Piddy
<?php

# Warnings Germany
# Namespace: warningsDE
# Meteotemplate Block

# Version 1.0 - Sep 12, 2016

if(file_exists("settings.php")){
include("settings.php");
}
else{
echo "Please go to your admin section and go through the settings for this block first.";
die();
}

// load theme
$designTheme = json_decode(file_get_contents("../../css/theme.txt"),true);
$theme = $designTheme['theme'];

include("../../../config.php");
include("../../../scripts/functions.php");

$languageRaw = file_get_contents($baseURL."lang/gb.php");
$language['gb'] = json_decode($languageRaw,true);
$languageRaw = file_get_contents($baseURL."lang/".$lang.".php");
$language[$lang] = json_decode($languageRaw,true);


if(!is_dir("cache")){
mkdir("cache");
}

if(file_exists("cache/warningsDE.txt")){
if (time()-filemtime("cache/warningsDE.txt") > 60 * 60) {
unlink("cache/warningsDE.txt");
}
}
if(file_exists("cache/warningsDE.txt")){
$rawData = file_get_contents("cache/warningsDE.txt");
}
else {
$urlWarnings = "http://www.dwd.de/DWD/warnungen/warnapp ... nings.json";
$rawData = file_get_contents($urlWarnings);
$rawData = str_replace("warnWetter.loadWarnings(","",$rawData);
$rawData = str_replace('Copyright Deutscher Wetterdienst"});','Copyright Deutscher Wetterdienst"}',$rawData);
file_put_contents("cache/warningsDE.txt",$rawData);
}

$data = json_decode($rawData,true);

if(array_key_exists('time',$data)){
$issueTime = $data['time']/1000;
$dataNA = false;
}
else{
$dataNA = true;
}
if(array_key_exists('warnings',$data)){
foreach($data['warnings'] as $warning){
$start = $warning[0]['start'];
$end = $warning[0]['end'];
$issued = $data['time'];
if($issued>=$start && $issued<=$end){
$warnings[] = $warning;
}
}
}


?>
<style>
.warningsDEHeading{
font-size: 1.4em;
font-weight: bold;
font-variant: small-caps;
}
.warningsDEHeadingSmall{
font-size: 1.1em;
font-weight: bold;
font-variant: small-caps;
}
#warningsDEMapOpener{
opacity: 0.8;
cursor: pointer;
}
#warningsDEMapOpener:hover{
opacity: 1;
}
</style>
<?php
if($dataNA){
echo lang("data currently not available",'c');
}
else{
if(count($warnings)==0){
?>
<br>
<table style="width:98%;margin:0 auto">
<tr>
<td style="width:100px">
<img src='homepage/blocks/warningsDE/icons/<?php echo $theme?>/warning.png' style="max-width:25px;width:100%" alt=''>
</td>
<td style="text-align:center">
<span style="font-size:1.5em;color:#59B300;font-variant:small-caps;padding-left:15px" class="shadow">
<?php echo lang('no warnings','c')?>
</span>
</td>
<td style="width:100px">
<span id="warningsDEMapOpener"><img src="http://www.dwd.de/DWD/warnungen/warnapp ... ap_shh.png" style="width:75%"></span>
</td>
</tr>
</table>
<?php
}
else{
?>
<table style="width:98%;margin:0 auto">
<tr>
<td style="width:100px">
<img src='homepage/blocks/warningsDE/icons/<?php echo $theme?>/warning.png' style="max-width:25px;width:100%" alt=''>
</td>
<td style="text-align:center">
<span style="font-size:1.5em;color:#d90000;font-variant:small-caps;padding-left:15px" class="shadow">
<?php echo lang('warnings','c')?>
</span>
</td>
<td style="width:100px">
<span id="warningsDEMapOpener"><img src="http://www.dwd.de/DWD/warnungen/warnapp ... ap_shh.png" style="width:75%"></span>
</td>
</tr>
</table>
<br>
<table style="width:98%;margin:0 auto" class="table">
<?php
foreach($warnings as $warning){
if($warning[0]['stateShort']==$defaultDEState){
?>
<tr>
<td style="text-align:justify;width:75%">
<span class="warningsDEHeading">
<?php echo $warning[0]['regionName']?>,
</span>
<span class="warningsDEHeadingSmall">
<?php echo $warning[0]['state']?>
</span>
<br>
<span style="font-weight:bold;font-size:0.9em">
<?php echo date($dateTimeFormat,($warning[0]['start']/1000))?> - <?php echo date($dateTimeFormat,($warning[0]['end']/1000))?>
</span>
<div style="margin-top:15px;width:100%;text-align:justify;font-size:0.8em">
<?php echo $warning[0]['description']?>
</div>
</td>
<td style="text-align:center;width:25%;padding:10px">
<span class="warningsDEHeadingSmall">
<?php echo $warning[0]['headline']?>
</span>
</td>
</tr>
<?php
}
}
?>
</table>
<div style="width:100%" class="details" id="warningsDEDetails">
<br>
<table style="width:98%;margin:0 auto" class="table">
<?php
foreach($warnings as $warning){
if($warning[0]['stateShort']!=$defaultDEState){
?>
<tr>
<td style="text-align:justify;width:75%">
<span class="warningsDEHeading">
<?php echo $warning[0]['regionName']?>,
</span>
<span class="warningsDEHeadingSmall">
<?php echo $warning[0]['state']?>
</span>
<br>
<span style="font-weight:bold;font-size:0.9em">
<?php echo date($dateTimeFormat,($warning[0]['start']/1000))?> - <?php echo date($dateTimeFormat,($warning[0]['end']/1000))?>
</span>
<div style="margin-top:15px;width:100%;text-align:justify;font-size:0.8em">
<?php echo $warning[0]['description']?>
</div>
</td>
<td style="text-align:center;width:25%;padding:10px">
<span class="warningsDEHeadingSmall">
<?php echo $warning[0]['headline']?>
</span>
</td>
</tr>
<?php
}
}
?>
</table>
</div>
<span class="more" onclick="txt = $('#warningsDEDetails').is(':visible') ? '<?php echo lang('more','l')?>' : '<?php echo lang('hide','l')?>';$('#warningsDEDetails').slideToggle(800);$(this).text(txt)">
<?php echo lang('more','l')?>
</span>
<br>
<div style="width:98%;margin:0 auto;text-align:center;font-size:0.8em">
<?php echo lang('data source','c')?>: Deutscher Wetterdienst
</div>
<?php
}
}
?>
<div id="warningsDEMap" style="display:none;text-align:center;padding-top:50px">
<img src="http://www.dwd.de/DWD/warnungen/warnapp ... ap_shh.png" style="height:75%">
</div>
<script>
$("#warningsDEMapOpener").click(function(){
$("#warningsDEMap").dialog('open');
})
dialogHeight = screen.height*0.8;
dialogWidth = screen.width*0.6;
$("#warningsDEMap").dialog({
modal: true,
autoOpen: false,
height: dialogHeight,
width: dialogWidth
});
</script>

Re: warningsDE

Posted: Sat Jan 29, 2022 4:32 pm
by davidefa
Currently there are no waning for state SHH ( see attached document ).
Not sure if this reflect a change in state definitions ( I'm not able to dig into dwd documentation https://www.dwd.de/DE/leistungen/opendata/opendata.html )
If this is the case and you are interested in retrieving only a subset of warning of a given state, we could expand the filtering specifying both state and regions of interest

P.S.
There is also a small bug to be corrected because only the first warning for each region is displayed

Re: warningsDE

Posted: Tue Feb 01, 2022 6:22 am
by Piddy
Boah keiner hier der ne Deutsche Wetterseite am laufen hat und den Block d warningsDE mit eingebunden hat.....

Re: warningsDE

Posted: Wed Aug 30, 2023 8:51 am
by Piddy
I have to try again, the cache file is updated, but nothing is displayed on the homepage, where is the error again?


{"time":1693384433000,"warnings":{"501000004":[{"state":"Schleswig-Holstein","type":1,"level":2,"start":1693378320000,"end":null,"regionName":"Elbe von Hamburg bis Cuxhaven","event":"BÖEN","headline":"Amtliche Warnung des Seewetterdienstes Hamburg vor BÖEN","instruction":"","description":"Strichweise Gewitterböen von 7 Beaufort aus Südwest.","stateShort":"SH","altitudeStart":null,"altitudeEnd":null}],"501000005":[{"state":"Schleswig-Holstein","type":1,"level":2,"start":1693378320000,"end":null,"regionName":"Nordfriesische Küste","event":"BÖEN","headline":"Amtliche Warnung des Seewetterdienstes Hamburg vor BÖEN","instruction":"","description":"Strichweise Gewitterböen von 7 Beaufort aus Südwest.","stateShort":"SH","altitudeStart":null,"altitudeEnd":null}],"501000001":[{"state":"Schleswig-Holstein","type":1,"level":2,"start":1693378320000,"end":null,"regionName":"Ostfriesische Küste","event":"BÖEN","headline":"Amtliche Warnung des Seewetterdienstes Hamburg vor BÖEN","instruction":"","description":"Strichweise Gewitterböen von 7 Beaufort aus Südwest.","stateShort":"SH","altitudeStart":null,"altitudeEnd":null}],"501000002":[{"state":"Schleswig-Holstein","type":1,"level":2,"start":1693378320000,"end":null,"regionName":"Helgoland","event":"BÖEN","headline":"Amtliche Warnung des Seewetterdienstes Hamburg vor BÖEN","instruction":"","description":"Strichweise Gewitterböen von 7 Beaufort aus Südwest.","stateShort":"SH","altitudeStart":null,"altitudeEnd":null}],"501000003":[{"state":"Schleswig-Holstein","type":1,"level":2,"start":1693378320000,"end":null,"regionName":"Elbe-/Wesermündung","event":"BÖEN","headline":"Amtliche Warnung des Seewetterdienstes Hamburg vor BÖEN","instruction":"","description":"Strichweise Gewitterböen von 7 Beaufort aus Südwest.","stateShort":"SH","altitudeStart":null,"altitudeEnd":null}]},"vorabInformation":{},"copyright":"Copyright Deutscher Wetterdienst"}