76 lines
2.3 KiB
Perl
76 lines
2.3 KiB
Perl
use Mojo::UserAgent;
|
|
#use Data::Printer;
|
|
use File::Slurp;
|
|
use JSON;
|
|
|
|
my $ua = Mojo::UserAgent->new;
|
|
my $tx = $ua->get('https://wetter.lauters.heim-server.de/current.html')->result->body;
|
|
|
|
my $netext = $tx =~ s/\R//rg;
|
|
|
|
my $wohin = '';
|
|
my $referenz = {
|
|
"uvindex" => "0",
|
|
"solarstrahlung" => "0",
|
|
"taupunkt" => "0",
|
|
"luftdruck" => "0",
|
|
"luftfeuchte" => "0",
|
|
"temp" => "0"
|
|
};
|
|
|
|
if ( -e $wohin.'wetter.json') {
|
|
my $red = read_file( $wohin. 'wetter.json');
|
|
$referenz = decode_json($red);
|
|
}
|
|
|
|
my $json = {
|
|
"uvindex" => "0",
|
|
"solarstrahlung" => "0",
|
|
"taupunkt" => "0",
|
|
"luftdruck" => "0",
|
|
"luftfeuchte" => "0",
|
|
"temp" => "0"
|
|
};
|
|
|
|
my @tr = $netext =~ /<tr>(.*?)<\/tr>/g;
|
|
|
|
for my $t ( @tr ) {
|
|
if ( $t =~ /<nobr>Temperatur Außen<\/nobr>/ ) {
|
|
my ($aktuell) = $t =~ /<b><font size="1">aktuell<\/font><\/b><br><b><font size="5">(.*?)°C<\/font><\/b/g;
|
|
$json->{temp} = $aktuell =~ s/,/\./r;
|
|
}
|
|
|
|
if ( $t =~ /<nobr>Luftfeuchte Außen<\/nobr>/ ) {
|
|
my ($aktuell) = $t =~ /<b><font size="1">aktuell<\/font><\/b><br><b><font size="5">(.*?)%<\/font><\/b/g;
|
|
$json->{luftfeuchte} = $aktuell;
|
|
}
|
|
|
|
if ( $t =~ /<nobr>Luftdruck<\/nobr>/ ) {
|
|
my ($aktuell) = $t =~ /<b><font size="1">aktuell<\/font><\/b><br><b><font size="5">(.*?)hPa<\/font><\/b/g;
|
|
$json->{luftdruck} = $aktuell =~ s/,/\./r;
|
|
}
|
|
|
|
if ( $t =~ /<nobr>Taupunkt<\/nobr>/ ) {
|
|
my ($aktuell) = $t =~ /<b><font size="1">aktuell<\/font><\/b><br><b><font size="5">(.*?)°C<\/font><\/b/g;
|
|
$json->{taupunkt} = $aktuell =~ s/,/\./r;
|
|
}
|
|
if ( $t =~ /<nobr>UV-Index<\/nobr>/ ) {
|
|
my ($aktuell) = $t =~ /<b><font size="1">aktuell<\/font><\/b><br><b><font size="5">(.*?)UV-I<\/font><\/b/g;
|
|
$json->{uvindex} = $aktuell =~ s/,/\./r;
|
|
}
|
|
if ( $t =~ /<nobr>Solarstrahlung<\/nobr>/ ) {
|
|
my ($aktuell) = $t =~ /<b><font size="1">aktuell<\/font><\/b><br><b><font size="5">(.*?)W\/m²<\/font><\/b/g;
|
|
$json->{solarstrahlung} = $aktuell =~ s/,/\./r;
|
|
}
|
|
}
|
|
|
|
my $aenderungen;
|
|
for my $ref ( keys %{$referenz} ) {
|
|
if ( $referenz->{$ref} ne $json->{$ref} ) {
|
|
$aenderungen = 1;
|
|
}
|
|
}
|
|
|
|
write_file( $wohin.'wetter.json', encode_json($json) ) if $aenderungen;
|
|
# write_file( "/var/www/html/wetter/wetter.json", encode_json($json) );
|