The Mac Observer

 
   
 
how do I run this perlscript i found?
Posted: 23 April 2002 08:34 PM [ Ignore ]
stars_big_1
Avatar
Total Posts:  4106
Joined  2001-12-26

found this perlscript at Mac OSX Hints

#!/usr/bin/perl
#
#  getWeather--a script to get weather information from Weather.com
#  by Mark T. Tomczak, 2002
#
$ZIPCODE=15213;
if($
#ARGV == 0)
{
  $ZIPCODE
=$ARGV[0];
  
$ZIPCODE =~m/ddddd/gi;
  if(
length($ZIPCODE) != 5)
  
{
    
print "Invalid zipcode. Please enter only a five-digit zipcode.n";
    exit;
  
}
}
open
(INPUT"wget http://www.weather.com/weather/local/$ZIPCODE -q -O-|");
@
stream=<INPUT>;
close(INPUT);
$stream=join(" ", @stream);
#extract the forecast
if($stream=~ m/<!-- insert forecast text -->.*</td>/gi)
{
  $forecast
=$&;
  
$forecast =~ s/<!-- insert forecast text -->//;
  
$forecast =~ s/</td>//;
}
else
{
  $forecast
"... umm... I'm not sure...";
}
#extract the temperature
if($stream=~ m/<!-- insert current temp -->.*?&deg;F/gi)
{
  $temp
=$&;
  
$temp =~ s/<!-- insert current temp -->//;
  
$temp =~ s/&deg;F//;
}
else
{
  $temp
"... umm... I'm not sure...";
}
# pick up on today's forecast
($stream=~m/<!-- insert load change day/date here -->/) || die "Couldn't parse weather information.";
  
$stream=$';
  $stream=~s/n//gi;
  $daycast=$stream;
  $daycast=~m/<TD CLASS="dataText" ALIGN="LEFT">/gi || die "Couldn'
t parse weather information.";
  $daycast=$';
  $daycast=~s/</TD>.*//gi;
#trim whitespace from the variable
$daycast=~s/^s*//gi;
$daycast=~s/s*$//gi;
#pick up today's high
$daytemps=$stream;
($daytemps=~/&nbsp;/gi) || die "
Couldn't parse weather information";
$stream=$'
;
$dayhigh=$stream;
$dayhigh =~ s/</TD>.*//gi;
$dayhigh =~ s/&deg;F.*//gi;
$dayhigh=~s/^s*//gi;
$dayhigh=~s/s*$//gi;
#pick up today's low
($daytemps=~m/&nbsp;/gi) || die "Couldn't parse weather information";
$stream=$;
$daylow=$stream;
$daylow =~ s/</TD>.*//gi;
$daylow =~ s/&deg;F.*//gi;
$daylow=~s/^s*//gi;
$daylow=~s/s*$//gi;
#Output the results.
$output="The current weather is $forecast, and the current temperature is $temp.nThe forcast for today is $daycast.";
if(
length($dayhigh) !=0)
{
  $output
=$output."nThe high is $dayhigh.";
}
if(length($daylow) !=0)
{
  $output
=$output."nThe low is $daylow.";
}
print "$outputn"

Its saved to my home partition (cleverly titled “Home”)

saved with SimpleText under the name “getWeather”

In the Terminal I type…

cd /Volumes/Home
chmod 755 getWeather
rehash
% ./getWeather 

then it spits this at me…

Couldnt parse weather informationat ./getWeather line 44. 


help? anyone? please!

not really important that i get this working, but it looks like fun… icon_biggrin.gif

 

 Signature 

-Louie

Profile
 
 
Posted: 23 April 2002 03:44 AM [ Ignore ] [ # 1 ]
Moderator
Total Posts:  3912
Joined  2001-07-13

Okay, here is the culprit:

($stream=~m/<!-- insert load change day/date here -->/) || die "Couldn't parse weather information."

My guess is that you don’t have wget installed (I don’t either), which the notes mention as a requirement.

 

 Signature 

Work is the curse of the drinking classes.
- Oscar Wilde

Profile
 
 
Posted: 23 April 2002 07:49 AM [ Ignore ] [ # 2 ]
stars_5
Total Posts:  1162
Joined  2001-11-02

hey cool!  (I’ve got wget installed) 

it tells me

The current weather is Mostly Cloudy, and the current temperature is 41.
The forcast 
for today is Partly Cloudy.
The high is 53.
The low is 39. 

I’ll have to see if I can get it to append the forecast for tomorrow too, then email it to myself daily icon_smile.gif

 

 Signature 

All statements are to be taken with a grain of salt

Profile
 
 
Posted: 23 April 2002 09:43 AM [ Ignore ] [ # 3 ]
stars_big_1
Avatar
Total Posts:  4106
Joined  2001-12-26

tbone1, thanks, reading the post on installing wget now

EDGar, rock on, it works!!

ps. if you get it to append “tomorrow’s forcast” can you post the upgraded script? actually, maybe a 2 day ahead forcast (current, tomorrow, and the next day) would be killer (anything beyond that isn’t accurate enough to listen to anyways)

 Signature 

-Louie

Profile
 
 
Posted: 23 April 2002 08:34 PM [ Ignore ] [ # 4 ]
stars_big_1
Avatar
Total Posts:  4106
Joined  2001-12-26

sweet.. got it working (with some help)

just had to install this… http://macosx.forked.net/ports/wget-1.8.1.pkg.tgz

and it worked!

but look at what it spat at me…..

The current weather is Mostly Cloudy, and the current temperature is 52.
The forcast for today is Rain / Snow Showers.
The high is 42.
The low is 23.

look at the current temperature, and look at the high for the day…. icon_biggrin.gif (keep in mind, its 12:30am here)

current weather is close… thermometer reads 48… just something geeky to play with i guess… but today looks like its going to be cold… i might sleep in icon_wink.gif

 

 Signature 

-Louie

Profile
 
 
   
 
 

Apple Stock Quote (AAPL)

Loading...

Hot Topics

TMO Express

Join the TMO Express Daily Newsletter to get the latest Mac headlines in your e-mail every weekday. Find out more!

Top Deals From DealBrothers.com

Recent Features

Support The Mac Observer

We noticed you may be running AdBlock on your computer. It takes real money to run this site and to deliver the news, tips, and opinions you love to read.

If you wish to block the ads that pay for the creation of our content, we ask that you instead support TMO Directly, either with a $5 monthly recurring contribution, or a one-time donation of any amount of your choice. Thanks!

Subscribe with Paypal Donate with Paypal