diff --git a/getwetter.pl b/getwetter.pl
index 13174a7..80a3943 100644
--- a/getwetter.pl
+++ b/getwetter.pl
@@ -1,69 +1,75 @@
use Mojo::UserAgent;
-use Data::Printer;
+#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 $tx = $ua->get('https://wetter.lauters.heim-server.de/current.html')->result->body;
-# # my $netext = $tx =~ s/\R//rg;
+my $netext = $tx =~ s/\R//rg;
-my $tx = $ua->get('https://wetter.lauters.heim-server.de/clientraw.txt')->result->body;
-append_file('clientraw.txt', "$tx");
+my $wohin = '';
+my $referenz = {
+ "uvindex" => "0",
+ "solarstrahlung" => "0",
+ "taupunkt" => "0",
+ "luftdruck" => "0",
+ "luftfeuchte" => "0",
+ "temp" => "0"
+};
-# my $red = read_file('clientraw.txt');
-my @read = split(' ', $tx);
-
-my $var = read_file('variablen.txt');
-my @vari = split(/\n/, $var);
-# p @vari;
-# p @read;
-
-my $c = 0;
-my $json = {};
-for my $v ( @read ) {
- if ( $vari[$c] =~ /,/ ) {
- my ($wert, $einheit, $jsonkey ) = split(',', $vari[$c]);
- if ( $jsonkey ) {
- $json->{$jsonkey} = $read[$c];
- }
- print "$wert: $read[$c] $einheit\n";
- }
-
- $c ++;
+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 = $red =~ /
(.*?)<\/tr>/g;
+my @tr = $netext =~ /
(.*?)<\/tr>/g;
-# for my $t ( @tr ) {
-# if ( $t =~ /Temperatur Außen<\/nobr>/ ) {
-# my ($aktuell) = $t =~ /aktuell<\/font><\/b>
(.*?)°C<\/font><\/b/g;
-# $json->{temp} = $aktuell =~ s/,/\./r;
-# }
+for my $t ( @tr ) {
+ if ( $t =~ /Temperatur Außen<\/nobr>/ ) {
+ my ($aktuell) = $t =~ /aktuell<\/font><\/b>
(.*?)°C<\/font><\/b/g;
+ $json->{temp} = $aktuell =~ s/,/\./r;
+ }
-# if ( $t =~ /Luftfeuchte Außen<\/nobr>/ ) {
-# my ($aktuell) = $t =~ /aktuell<\/font><\/b>
(.*?)%<\/font><\/b/g;
-# $json->{luftfeuchte} = $aktuell;
-# }
+ if ( $t =~ /Luftfeuchte Außen<\/nobr>/ ) {
+ my ($aktuell) = $t =~ /aktuell<\/font><\/b>
(.*?)%<\/font><\/b/g;
+ $json->{luftfeuchte} = $aktuell;
+ }
-# if ( $t =~ /Luftdruck<\/nobr>/ ) {
-# my ($aktuell) = $t =~ /aktuell<\/font><\/b>
(.*?)hPa<\/font><\/b/g;
-# $json->{luftdruck} = $aktuell =~ s/,/\./r;
-# }
+ if ( $t =~ /Luftdruck<\/nobr>/ ) {
+ my ($aktuell) = $t =~ /aktuell<\/font><\/b>
(.*?)hPa<\/font><\/b/g;
+ $json->{luftdruck} = $aktuell =~ s/,/\./r;
+ }
-# if ( $t =~ /Taupunkt<\/nobr>/ ) {
-# my ($aktuell) = $t =~ /aktuell<\/font><\/b>
(.*?)°C<\/font><\/b/g;
-# $json->{taupunkt} = $aktuell =~ s/,/\./r;
-# }
-# if ( $t =~ /UV-Index<\/nobr>/ ) {
-# my ($aktuell) = $t =~ /aktuell<\/font><\/b>
(.*?)UV-I<\/font><\/b/g;
-# $json->{uvindex} = $aktuell =~ s/,/\./r;
-# }
-# if ( $t =~ /Solarstrahlung<\/nobr>/ ) {
-# my ($aktuell) = $t =~ /aktuell<\/font><\/b>
(.*?)W\/m²<\/font><\/b/g;
-# $json->{solarstrahlung} = $aktuell =~ s/,/\./r;
-# }
-# }
+ if ( $t =~ /Taupunkt<\/nobr>/ ) {
+ my ($aktuell) = $t =~ /aktuell<\/font><\/b>
(.*?)°C<\/font><\/b/g;
+ $json->{taupunkt} = $aktuell =~ s/,/\./r;
+ }
+ if ( $t =~ /UV-Index<\/nobr>/ ) {
+ my ($aktuell) = $t =~ /aktuell<\/font><\/b>
(.*?)UV-I<\/font><\/b/g;
+ $json->{uvindex} = $aktuell =~ s/,/\./r;
+ }
+ if ( $t =~ /Solarstrahlung<\/nobr>/ ) {
+ my ($aktuell) = $t =~ /aktuell<\/font><\/b>
(.*?)W\/m²<\/font><\/b/g;
+ $json->{solarstrahlung} = $aktuell =~ s/,/\./r;
+ }
+}
-write_file( 'wetter.json', encode_json($json) );
+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) );
diff --git a/getwetter_test.pl b/getwetter_test.pl
new file mode 100644
index 0000000..13174a7
--- /dev/null
+++ b/getwetter_test.pl
@@ -0,0 +1,69 @@
+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 $tx = $ua->get('https://wetter.lauters.heim-server.de/clientraw.txt')->result->body;
+append_file('clientraw.txt', "$tx");
+
+# my $red = read_file('clientraw.txt');
+my @read = split(' ', $tx);
+
+my $var = read_file('variablen.txt');
+my @vari = split(/\n/, $var);
+# p @vari;
+# p @read;
+
+my $c = 0;
+my $json = {};
+for my $v ( @read ) {
+ if ( $vari[$c] =~ /,/ ) {
+ my ($wert, $einheit, $jsonkey ) = split(',', $vari[$c]);
+ if ( $jsonkey ) {
+ $json->{$jsonkey} = $read[$c];
+ }
+ print "$wert: $read[$c] $einheit\n";
+ }
+
+ $c ++;
+}
+
+
+# my @tr = $red =~ /(.*?)<\/tr>/g;
+
+# for my $t ( @tr ) {
+# if ( $t =~ /Temperatur Außen<\/nobr>/ ) {
+# my ($aktuell) = $t =~ /aktuell<\/font><\/b>
(.*?)°C<\/font><\/b/g;
+# $json->{temp} = $aktuell =~ s/,/\./r;
+# }
+
+# if ( $t =~ /Luftfeuchte Außen<\/nobr>/ ) {
+# my ($aktuell) = $t =~ /aktuell<\/font><\/b>
(.*?)%<\/font><\/b/g;
+# $json->{luftfeuchte} = $aktuell;
+# }
+
+# if ( $t =~ /Luftdruck<\/nobr>/ ) {
+# my ($aktuell) = $t =~ /aktuell<\/font><\/b>
(.*?)hPa<\/font><\/b/g;
+# $json->{luftdruck} = $aktuell =~ s/,/\./r;
+# }
+
+# if ( $t =~ /Taupunkt<\/nobr>/ ) {
+# my ($aktuell) = $t =~ /aktuell<\/font><\/b>
(.*?)°C<\/font><\/b/g;
+# $json->{taupunkt} = $aktuell =~ s/,/\./r;
+# }
+# if ( $t =~ /UV-Index<\/nobr>/ ) {
+# my ($aktuell) = $t =~ /aktuell<\/font><\/b>
(.*?)UV-I<\/font><\/b/g;
+# $json->{uvindex} = $aktuell =~ s/,/\./r;
+# }
+# if ( $t =~ /Solarstrahlung<\/nobr>/ ) {
+# my ($aktuell) = $t =~ /aktuell<\/font><\/b>
(.*?)W\/m²<\/font><\/b/g;
+# $json->{solarstrahlung} = $aktuell =~ s/,/\./r;
+# }
+# }
+
+write_file( 'wetter.json', encode_json($json) );