#!/usr/bin/perl use Weather::Underground; use strict; use warnings; my($Clouds, $Conditions, $Place, $Pressure, $Pressure_in, $Pressure_kpa, $MyVar); foreach $MyVar (\$Clouds, \$Conditions, \$Place, \$Pressure, \$Pressure_in, \$Pressure_kpa, \$MyVar) { $$MyVar = ''; } if ($ARGV[0]) { $Place = $ARGV[0]; } else { $Place = 'yow'; } my($weather) = Weather::Underground->new( place => "$Place", debug => 0, cache_file => "/tmp/.wu_cache", cache_max_age => "360" # Will query server if cache data for a location is older than this (in seconds) ) || die "Error, could not create new weather object: $@\n"; my($arrayref) = $weather->get_weather() || die "Error, calling get_weather() failed: $@\n"; # If Pressure exists, clean it up if($arrayref->[0]->{pressure}) { $Pressure = $arrayref->[0]->{pressure}; if( $Pressure =~ /\s*([^ ]+)\s+in\s+([^ ]+)\s+hPa\s*(.*)/ ) { $Pressure_in = $1; $Pressure_kpa = $2/10; $Pressure = $3; $Pressure =~ s/ //g; } } # Sometimes the $Conditions output is not in $Clouds. Put it there if missing if( $arrayref->[0]->{clouds} ) { $Clouds = $arrayref->[0]->{clouds}; if( $arrayref->[0]->{conditions} ) { if( ! $Clouds =~ /$Conditions/ ) { $Clouds = "$Conditions $Clouds"; } } } print('Current Conditions in ', ($arrayref->[0]->{place} || 'N/A'), ' as of ', ($arrayref->[0]->{updated} || 'N/A'), ": ", ($Clouds || 'N/A'), ', Temperature: ', ($arrayref->[0]->{temperature_celsius} || 'N/A'), '°C / ', ($arrayref->[0]->{temperature_fahrenheit} || 'N/A'), '°F, Humidity: ', ($arrayref->[0]->{humidity} || 'N/A' ), '%, Pressure: ', ($Pressure_in || 'N/A'), " in HG / ", ($Pressure_kpa || 'N/A'), ' kPa ', ($Pressure || ''), ", Visibility: ", ($arrayref->[0]->{visibility_kilometers} || 'N/A'). ' km/ ', ($arrayref->[0]->{visibility_miles} || 'N/A'), " miles, Winds: ", ($arrayref->[0]->{wind_direction} || 'N/A'), ' ', ($arrayref->[0]->{wind_kilometersperhour} || 'N/A')," kmph / ", ($arrayref->[0]->{wind_milesperhour}||'N/A'), ' mph, ', 'Dewpoint: ', ($arrayref->[0]->{dewpoint_celsius} || 'N/A'), "°C / ", ($arrayref->[0]->{dewpoint_fahrenheit} || 'N/A'), '°F, Moonphase: ', ($arrayref->[0]->{moonphase} || 'N/A'), ", Moonrise: ", ($arrayref->[0]->{moonrise} || 'N/A'), ', Moonset: ', ($arrayref->[0]->{moonset} || 'N/A'),', Sunrise: ', ($arrayref->[0]->{sunrise} || 'N/A'), ', Sunset: ', ($arrayref->[0]->{sunset} || 'N/A'), "\n");