########################################### # Waterscore -- 2006, Mike Schilli # ########################################### package Waterscore; use base Exporter; @EXPORT_OK = qw(waterscore); use strict; use warnings; use Weather::Com; use Log::Log4perl qw(:easy); my $PARTNER = "1031443804"; my $LICENSE = "8d88149d90fec933"; ########################################### sub waterscore { ########################################### my($loc) = @_; my $w = Weather::Com->new( current => 1, units => "m", timeout => 250, partner_id => $PARTNER, license => $LICENSE, ); my $now = $w->get_weather($loc); return undef unless defined $now; my($cond, $temp, $humi) = map { $now->{cc}->{$_} } qw(t tmp hmid); DEBUG "$cond, $temp C, $humi%"; my $score = 50; $score += 50 if $humi < 50; $score -= 30 if $cond =~ /Showers/; $score -= 80 if $cond =~ /Rain/; $score += 80 if $cond =~ /Sunny/; if($temp > 20) { $score += ($temp-15)*10; } $score = 100 if $score > 100; $score = 0 if $score < 0; DEBUG "Score: $score"; return $score; } 1;