#!/usr/bin/env perl # Written by Shane Young # JeopardyTempest@yahoo.com # January 03 use LWP::Simple; # provides ability to access files via http, use POSIX; #-------Constants------- $wxpath = "/usr/local/bin/"; # Weather command path # *** if program stops working, this is a likely culprit $nwsruncommand = "fp4"; # NWS command in weather program # /// website model sources /// $sourcewebpage1="http://www.nws.noaa.gov/cgi-bin/mos/get"; # hash with each model name corresponding to the weather # command or website %modellocation = ( "NGM" => "ngmmos", "GFS" => $sourcewebpage1."mav.pl?sta=", "ETA" => "etamos", ); #-------Section for getting/cleaning site choice $site = @ARGV[0]; # site is assigned first command line param chomp $site; # removes spaces and such while ($site eq "") # if no site as arguement, loop gets site from user { print "Enter Site: "; $site = ; chomp $site; } chomp $site; if ($string.length($site) == 3) # if three characters are entered, then it adds the k in front of { # station (for web addys) $site = "K" . $site; } $site = "\U$site\E"; # change station to uppercase (for website parsing) #-------Getting Model Data ---------- $modeldata = ""; # initializes the modeldata to empty foreach $model (keys %modellocation) # goes through each model in array, setting $model to model name and { # $modellocation{model} is location if ($modellocation{$model} =~ /\./) # if modellocation has a period, it is a website. { # Otherwise it is a rossby command. $content = get(($modellocation{$model}).$site); # imports website files to $content if ($content eq "") # if website is empty, print error message { print "webpage $modellocation{$model}.$site does not exist, $model unavailable"; } $content =~ m#
\n(.*?)
#isg; # line for extracting only model from webpage. Currently # based on
 and 
webpage formatting tags. $match = $1; @downloaded = split /\n[\s?]/,$match; # this and next 2 lines remove leading spaces in downloaded model @downloaded[0] =~ s/^\s+//; $downloadstr = join("\n", @downloaded); $modeldata = $modeldata . $downloadstr . "\n"; # adds the extracted data to data collection ($1 = found string) } else { # builds the complete command from the path and modellocation var $command = $wxpath."weather -c ".$modellocation{$model}." ".$site." l"; $modeldata = $modeldata . `$command` . "\n"; # runs command and appends output to modeldata compilation. } } $command = $wxpath."weather -c ".$nwsruncommand." ".$site." l"; # sets command for getting NWS numbers. $modeldata = $modeldata . "NWS FP4 forecast for $site\n"; # Print formatting data for NWS numbers. $modeldata = $modeldata . `$command` . "\n"; # runs NWS data command print $modeldata; # prints out the model data #---------Putting together everything # print time ran #print "connecting to: $filename\n"; #$content=get($filename) or die("no $filename, die"); #open (OUT,">website.html"); #print OUT $content; #close (OUT);