#!/usr/bin/perl # # TEMP.PL - Get local temperature report from weather.com by ZIP code. # By Greg Palmier # Derived from DICT.PL by Cancer Omega # Updated on 09/10/2002 by Cancer Omega to account for changes # to weather.com's HTML response. # $date=`/bin/date +%m%d%y%H%M%S`;chomp($date); # Date in MMDDYYHHMMSS format $zip=shift(@ARGV);$zip=~s/ //g; # Read command-line variable $url="http://www.weather.com/weather/local/"; # weather.com URL $temp="/tmp/temp."."$date"; # Scratch file for processing $wget="/usr/local/bin/wget"; # Location of WGET # if ($zip ne "") { system(`$wget -q $url$zip?whatprefs= --output-document=$temp`); } else { print"\nRun as: $0 \n\n";exit 1; } open (INPUT,"$temp")||die("Can't open $temp!"); while () { chomp($_); if ($_=~/Local Forecast for/i) { $_=~s/Home<\/A> > //i; $_=~s/Local Forecast for (.*?)<\/B>/$1/; $location="$_"; } if ($_=~"-- insert current t") { $_=~s/\s+/ /g; $_=~s/ //; $_=~s/<\!-- insert current tempature --> (.*?)<\/B>/$1/i; $_=~s/\°/° /; $conditions="It is"."$_"."in "; last; } } close (INPUT); print "\n$conditions$location\n";system(`/usr/bin/rm $temp`);