#!/usr/bin/perl -w # Get the site code. my $site_code = shift @ARGV; die "Usage: $0 \n" unless $site_code; # Get the modules we need. use Data::Dumper; use Geo::METAR; use LWP::UserAgent; use strict; my $ua = new LWP::UserAgent; my $req = new HTTP::Request GET => "http://weather.noaa.gov/cgi-bin/mgetmetar.pl?cccc=$site_code"; my $response = $ua->request($req); if (!$response->is_success) { print $response->error_as_HTML; my $err_msg = $response->error_as_HTML; warn "$err_msg\n\n"; die "$!"; } else { # Yep, get the data and find the METAR. my $m = new Geo::METAR; $m->debug(0); my $data; $data = $response->as_string; # grap response $data =~ s/\n//go; # remove newlines $data =~ m/($site_code\s\d+Z.*?)metar($metar); # Here we will take the information from the module and put it into our variables. my $f_temp = int($m->TEMP_F) ; my $time = $m->TIME; my @sky_conds= @{$m->SKY()}; my $wind = int($m->WIND_MPH); my $w_dir = $m->WIND_DIR_ENG; my $gust = $m->WIND_GUST_MPH; my $vis =$m->VISIBILITY; my @cur_weather = @{$m->WEATHER()}; my $dew = $m->F_DEW; my $bar = $m->ALT; my $tz_adjust = -4; #to adjust the time zone so that the metar data is in local time. #lets play with the time a litte bit now $time =~s/UTC//go; $vis =~s/Statute//go; my $hours; my $minutes; ($hours, $minutes) = ($time =~ /(\d\d):(\d\d)/); my $local_hours = ($hours + $tz_adjust); #now we need to see if the wind is gusting my $gusting; if ($gust) { $gusting =", gusting to $gust mph | "; } else { $gusting =" | "; } #the program wouldn't be any good without some output...so here it is. print "Conditions as of $local_hours:$minutes |"; print " @sky_conds "; print "$f_temp Degrees "; if (@cur_weather) { print "@cur_weather | "; } else{ print "| "; } print "visibility is $vis | $w_dir winds blowing at $wind mph"; print "$gusting"; print "barometer at $bar inches \n"; print @cur_weather; } # end else exit; __END__ #### #avoid flicker double_buffer yes #own window to run simultanious 2 or more conkys own_window yes own_window_transparent no own_window_type normal own_window_hints undecorate,sticky,skip_taskbar,skip_pager #borders draw_borders no border_margin 1 #shades draw_shades no #position gap_x 6 gap_y 6 alignment top_left #behaviour update_interval 900 #colour default_color 8f8f8f #default_shade_color 000000 own_window_colour 262626 #font use_xft yes xftfont bauhaus:pixelsize=10 #to prevent window from moving use_spacer no minimum_size 1268 0 #mpd TEXT ${voffset -1} ${color white}${font Liberation Sans:style=Bold:size=10}${execi 300 perl ~/perl/conky_weather.pl KISP}