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) );