add wetter.at.pl
authorgregor herrmann <gregor@toastfreeware.priv.at>
Thu, 10 May 2018 18:56:51 +0000 (20:56 +0200)
committergregor herrmann <gregor@toastfreeware.priv.at>
Thu, 10 May 2018 18:56:51 +0000 (20:56 +0200)
perl script to scrape weather data for obsteig from wetter.at

wetter.at.pl [new file with mode: 0755]

diff --git a/wetter.at.pl b/wetter.at.pl
new file mode 100755 (executable)
index 0000000..87fafa5
--- /dev/null
@@ -0,0 +1,73 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use 5.010;
+
+use Web::Scraper;
+use HTTP::Tiny;
+use utf8::all;
+
+my $url      = 'http://www.wetter.at/wetter/oesterreich/tirol/obsteig';
+my $response = HTTP::Tiny->new->get($url);
+
+# don't die. the server returns 500 _and_ a valid content.
+# die "Failed to get '$url'.\n" unless $response->{success};
+
+my $body = $response->{content};
+
+my $s = scraper {
+    process "div.dayInfo",  "dayInfo" => "TEXT";
+    process "span.sunUp",   "sunUp"   => "TEXT";
+    process "span.sunDown", "sunDown" => "TEXT";
+    process "div.boxNow",   "boxNow"  => scraper {
+        process "div.title",    "title"    => "TEXT";
+        process "div.temp",     "temp"     => "TEXT";
+        process "div.icontext", "icontext" => "TEXT";
+        process "div.rain",     "rain"     => "TEXT";
+    };
+
+};
+
+my $res = $s->scrape($body);
+
+my $timeregexp = qr/^.*?([0-9:]+).*?$/;
+
+( my $date    = $res->{dayInfo} ) =~ s/^.*, (\d+)\.(\d+)\.(\d+)$/$3-$2-$1/;
+( my $time    = $res->{boxNow}->{title} ) =~ s/$timeregexp/$1/;
+( my $sunup   = $res->{sunUp} ) =~ s/$timeregexp/$1/;
+( my $sundown = $res->{sunDown} ) =~ s/$timeregexp/$1/;
+( my $temp    = $res->{boxNow}->{temp} )
+    =~ s/Â?°//;    # real °, and "something" before?!
+my ( $weather, $clouds )
+    = $res->{boxNow}->{icontext} =~ m|^([\w\s]+)\((\d+)% .*$|;
+my ( $rain, $wind )
+    = $res->{boxNow}->{rain} =~ m|Niederschlag: (.+)Wind: (.+)|;
+
+say 'Wetter in Obsteig (von wetter.at)';
+say '---------------------------------';
+say "Datum:\t$date";
+say "Zeit:\t$time";
+say "Sonne↑:\t$sunup";
+say "Sonne↓:\t$sundown";
+say "Temp:\t$temp°C";
+say "Nied.:\t$rain";
+say "Wind:\t$wind";
+say "Wetter:\t$weather";
+say "Bewölk:\t$clouds%";
+
+say '';
+say "$date;$time;$sunup;$sundown;$temp;$rain;$wind;$weather;$clouds";
+
+__END__
+
+=head1 NAME
+
+wetter.at.pl - show weather information about Obsteig from wetter.at
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright 2017-2018, gregor herrmann <gregor@toastfreeware.priv.at>
+
+Released under the same terms as Perl 5.
+