The weather outside is frightful
Here, code to grab weather from rssweather.com. Merry Christmas, don’t say I never did anything for you.
#!/usr/bin/perl -w
use LWP::UserAgent;
%urls = (
'newport' =>
'http://www.rssweather.com/rss.php?config=&forecast=zandh'
.'&place=newport+beach'
.'&state=ca&zipcode='
.'&country=us'
.'&county=06059'
.'&zone=caz042&alt=rss20a',
);
$ua = LWP::UserAgent->new;
$data = '';
if (! defined($city = shift))
{
$city = (keys %urls)[0];
}
if ($city eq '-')
{
$data .= <> while (! eof STDIN);
}
else
{
$url = $urls{$city};
$data = $ua->get($url);
die $data->status_line if (! $data->is_success);
$data = $data->content;
}
for (split /\n/, $data)
{
s/\°/ deg /g;
if (/<title>(.*?),\s/ && ! exists $data{'city'})
{
$data{'city'} = $1;
}
if (/<span class="sky">(.*?)<\/span>/)
{
$data{'sky'} = $1;
}
elsif (/<dd id="(\S+)" style="display: inline;">(.*?)<\/dd>/)
{
$data{$1} = $2;
}
}
if (exists $data{'winddir'})
{
$data{'winddir'} = (split /\s+/, $data{'winddir'}, 2)[0];
}
else
{
$data{'winddir'} = "?";
}
$data{'city'} = (split /\s+/, $data{'city'}, 2)[0];
printf "%s\nsky: %s\n"
."temp: %s\n"
."chill: %s\n"
."humid: %s\n"
."wind: %s \@ %s\n"
."vis: %s\n",
$data{'city'},
$data{'sky'},
$data{'heatindex'},
$data{'windchill'},
$data{'humidity'},
$data{'winddir'},
$data{'windspeed'},
$data{'visibility'};

No comments yet.