#!/usr/bin/perl -w ############################################################### # The Weather Note program downloads weather inforamtion from the net, # extracts desired data and then displays it using the perl module GD.pm. # The GD.pm enables a picture to be used as a background or it has tools # for creating image graphics. Once the image is incorporated, text can be # overlayed. # Author: Mackie Zwald # Date: April 12, 2000 # Program Name: Weather Note ############################################################### use GD #Download the current weather information and save it to a file. system ("lynx -dump http://www.wunderground.com/US/OH/Columbus.html >0409WundWeath"); #Open the file and extract the temperature, wind, humidity and current conditions. open (WEATH_INFO, "0409WundWeath") || die "no WundWeath today: $!"; while () { if (/Temperature\s\d+.*/) { @temp_info = split; shift(@temp_info); } if (/^\s+\bWind\b.*mph/) { @wind_info = split; } if (/^\s+Wind\sCalm/) { @wind_info = split; } if (/Humidity\s\d\d/) { @humid_info = split; } if (/^\s+Conditions/) { @condition_info = split; shift(@condition_info); } if (/Updated:/) { @time_info = split; shift @time_info; } } close WEATH_INFO; #The next 5 lines were included to test the information that had been downloaded. #You may uncomment them to see if the program is obtaining the right information. #print "@temp_info #@wind_info #@condition_info #@humid_info #@time_info\n"; #Next select the appropriate image to go with the current weather condition. #The default is the "sunny" image because I am an optimist. while (<@condition_info>) { if ($condition_info[0] =~ /partly/i && $condition_info[1] =~ /cloudy/i) { $image_png = "partlycloudy.png"; }elsif ($condition_info[1] =~ /clouds/i) { $image_png = "partlycloudy.png"; }elsif ($condition_info[0] =~ /rain/i) { $image_png = "rain.png"; }elsif ($condition_info[1] =~ /rain/i) { $image_png = "rain.png"; }elsif ($condition_info[0] =~ /mist/i) { $image_png = "rain.png"; }elsif ($condition_info[0] =~ /mostly/i && $condition_info[1] =~ /cloudy/i) { $image_png = "mostlycloudy.png"; }elsif ($condition_info[0] =~ /partly/i && $condition_info[1] =~ /sunny/i) { $image_png = "partlycloudy.png"; }else { $image_png = "sunny.png"; } } #Open the image open (PNG, $image_png) || die "couldn't open $image_png $!"; $myImage = newFromPng GD::Image(\*PNG) || die; close PNG; #allocate colors for the text $black = $myImage->colorAllocate(0,0,0); #Put the text onto the image. $myImage->string(gdMediumBoldFont,30,5,"Columbus, OH",$black); $myImage->string(gdMediumBoldFont,45,20,"@time_info[4,5]",$black); $myImage->string(gdGiantFont,55,35,"@temp_info",$black); $myImage->string(gdSmallFont,10,50,"@wind_info[0,1,2]",$black); $myImage->string(gdSmallFont,20,60,"@wind_info[3,4]",$black); $myImage->string(gdSmallFont,10,70,"@humid_info",$black); $myImage->string(gdSmallFont,10,80,"@condition_info",$black); $myImage->string(gdSmallFont,10,90,"at @time_info[0,1]",$black); binmode STDOUT; #The "$png_data" section sends the script output to the screen (DISPLAY) or to a file #(weath_note_img.png). You should comment or uncomment the desired section. #For our puposes we send it to a file that is referenced on a html page. #$png_data = $myImage->png; # open (DISPLAY,"| display -") || die; # binmode DISPLAY; # print DISPLAY $png_data; # close DISPLAY; $png_data = $myImage->png; open (OUT, ">weath_note_img.png") || die "$0:couldn't open weath_note_img.png\n"; binmode OUT; print OUT "$png_data"; close OUT;