warningsDE

Post Reply
Piddy
Observer
Observer
Posts: 31
Joined: Fri Apr 20, 2018 6:54 am
Station model: Davis Pro 2
Software: Weather Display

warningsDE

Post by Piddy » Sat Jan 29, 2022 7:28 am

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!
Image

davidefa
Expert
Expert
Posts: 862
Joined: Tue Jan 12, 2021 8:03 am
Location: Italy
Station model: WH2650
Software: WH2650 (direct upload)
Contact:

Re: warningsDE

Post by davidefa » Sat Jan 29, 2022 11:05 am

What your state short name ( as setup in the block ) and full name?
Image

Piddy
Observer
Observer
Posts: 31
Joined: Fri Apr 20, 2018 6:54 am
Station model: Davis Pro 2
Software: Weather Display

Re: warningsDE

Post by Piddy » Sat Jan 29, 2022 11:14 am

Short name SHH Schleswig-Holstein, Kreis Plön, Kreis Ostholstein
Image

Piddy
Observer
Observer
Posts: 31
Joined: Fri Apr 20, 2018 6:54 am
Station model: Davis Pro 2
Software: Weather Display

Re: warningsDE

Post by Piddy » Sat Jan 29, 2022 11:18 am

<?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>
Image

davidefa
Expert
Expert
Posts: 862
Joined: Tue Jan 12, 2021 8:03 am
Location: Italy
Station model: WH2650
Software: WH2650 (direct upload)
Contact:

Re: warningsDE

Post by davidefa » Sat Jan 29, 2022 4:32 pm

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
Attachments
w1.zip
(3.76 KiB) Downloaded 47 times
Image

Piddy
Observer
Observer
Posts: 31
Joined: Fri Apr 20, 2018 6:54 am
Station model: Davis Pro 2
Software: Weather Display

Re: warningsDE

Post by Piddy » Tue Feb 01, 2022 6:22 am

Boah keiner hier der ne Deutsche Wetterseite am laufen hat und den Block d warningsDE mit eingebunden hat.....
Image

Piddy
Observer
Observer
Posts: 31
Joined: Fri Apr 20, 2018 6:54 am
Station model: Davis Pro 2
Software: Weather Display

Re: warningsDE

Post by Piddy » Wed Aug 30, 2023 8:51 am

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"}
Image

Post Reply