#!/usr/bin/perl # # runs every hour. fetches website from env canada that has # current winnipeg temperature. use LWP::Simple; use Time::Local; #declare trim function sub trim($); $datestamp = time; $url = sprintf "http://www.weatheroffice.gc.ca/city/pages/mb-38_metric_e.html"; $content = get($url); $pattern = "\°C"; $t_found= 0; foreach $line (split /\n/ , $content) { if ($t_found == 1 && $line =~ m/$pattern/) { $line = trim($line); $line = substr ($line, 4, index($line, "&")-4); $temp = $line; system("rrdtool update /home/alex/furnace/climate.rrd $datestamp:$temp:U"); } if ($line =~ m/Temperature/) { $t_found = 1; } else { $t_found = 0; } } #trim subroutine sub trim($) { my $str = shift; $str =~ s/^\s+//; $str =~ s/\s+$//; return $str }