2019-06-26 18:34:19 +02:00
|
|
|
#!/usr/bin/perl -I /home/msmud/lib/lib/perl5/site_perl/5.10.0/
|
2007-05-20 22:44:44 +02:00
|
|
|
|
2017-03-05 22:33:31 +01:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
2007-05-20 22:44:44 +02:00
|
|
|
use LWP::Simple;
|
|
|
|
|
|
|
|
my ($text, $weather, $location, $date, $i, $day, @days);
|
|
|
|
|
2019-05-28 18:19:42 +02:00
|
|
|
if ($#ARGV < 0)
|
2007-05-20 22:44:44 +02:00
|
|
|
{
|
|
|
|
print "Try again. Please specify the location you would like weather for.\n";
|
|
|
|
die;
|
|
|
|
}
|
2019-06-26 18:34:19 +02:00
|
|
|
|
2007-05-20 22:44:44 +02:00
|
|
|
$location = join("+", @ARGV);
|
|
|
|
|
|
|
|
$location =~ s/,/%2C/;
|
|
|
|
|
2019-05-28 18:19:42 +02:00
|
|
|
if ($location =~ m/\+-(.*)/)
|
2007-05-20 22:44:44 +02:00
|
|
|
{
|
|
|
|
$date = $1;
|
|
|
|
$location =~ s/\+-.*//;
|
|
|
|
}
|
|
|
|
|
|
|
|
$i = 0;
|
|
|
|
|
|
|
|
$text = get("http://weather.yahoo.com/search/weather2?p=$location");
|
|
|
|
|
|
|
|
$location =~ s/\+/ /g;
|
|
|
|
$location =~ s/%2C/,/g;
|
|
|
|
|
2019-05-28 18:19:42 +02:00
|
|
|
if ($text =~ m/No match found/)
|
2007-05-20 22:44:44 +02:00
|
|
|
{
|
2019-06-26 18:34:19 +02:00
|
|
|
print "$location is not a valid location for this service.\n";
|
2007-05-20 22:44:44 +02:00
|
|
|
die;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $found = 0;
|
|
|
|
my $buf;
|
|
|
|
|
|
|
|
|
2019-05-28 18:19:42 +02:00
|
|
|
if ($text =~ m/location matches\:/g)
|
2007-05-20 22:44:44 +02:00
|
|
|
{
|
|
|
|
$buf = "Multiple locations found: ";
|
|
|
|
|
2019-05-28 18:19:42 +02:00
|
|
|
while ($text =~ m/<a\shref="\/forecast\/(.*?)">(.*?)<\/a>/g)
|
2007-05-20 22:44:44 +02:00
|
|
|
{
|
|
|
|
$i = $1;
|
|
|
|
$weather = $2;
|
|
|
|
|
|
|
|
$weather =~ s/<b>//g;
|
|
|
|
$weather =~ s/<\/b>//g;
|
|
|
|
$weather =~ s/^\s+//;
|
|
|
|
|
2019-06-26 18:34:19 +02:00
|
|
|
$buf = $buf . "$weather - ";
|
2007-05-20 22:44:44 +02:00
|
|
|
|
2019-05-28 18:19:42 +02:00
|
|
|
if ($location =~ m/$weather/i)
|
2007-05-20 22:44:44 +02:00
|
|
|
{
|
|
|
|
$text = get("http://weather.yahoo.com/forecast/$i");
|
|
|
|
$found = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$buf = $buf. "please specify one of these.\n";
|
|
|
|
if (not $found)
|
|
|
|
{
|
|
|
|
print $buf;
|
|
|
|
die;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-26 18:34:19 +02:00
|
|
|
my ($update, $temp, $high, $low, $tempc, $highc, $lowc, $cond,
|
|
|
|
$today, $tonight, $country, $state, $city, $humid, $wind,
|
2007-05-20 22:44:44 +02:00
|
|
|
$sunup, $sundown, $feels, $feelsc);
|
|
|
|
|
|
|
|
$text =~ m/<a href="\/">Weather<\/a>\s>/g;
|
|
|
|
$text =~ m/<a href=.*?>(.*?)<\/a>\s>/g;
|
|
|
|
$country = $1;
|
|
|
|
|
2019-05-28 18:19:42 +02:00
|
|
|
if ($country eq "North America")
|
2007-05-20 22:44:44 +02:00
|
|
|
{
|
|
|
|
$text =~ m/<a href=.*?>(.*?)<\/a>\s>/g;
|
|
|
|
$country = $1;
|
|
|
|
}
|
|
|
|
|
2019-06-26 18:34:19 +02:00
|
|
|
if ($country ne "Canada")
|
2007-05-20 22:44:44 +02:00
|
|
|
{
|
|
|
|
$text =~ m/<a href=.*?>(.*?)<\/a>\s>/g;
|
|
|
|
$state = $1;
|
|
|
|
}
|
|
|
|
|
|
|
|
$text =~ m/^(.*?)<\/b><\/font>/mg;
|
|
|
|
$city = $1;
|
|
|
|
|
|
|
|
$update = $1
|
|
|
|
if $text =~ m/at:\s(.*?)<\/font><\/td>/gi;
|
|
|
|
|
|
|
|
|
2019-06-26 18:34:19 +02:00
|
|
|
while ($text =~
|
2007-05-20 22:44:44 +02:00
|
|
|
m/<td\swidth\=\".*?align\=center\scolspan\=.*?\sface\=.*?\s.*?<b>(.*?)<\/b>/g)
|
|
|
|
{
|
|
|
|
push(@days, $1);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach $day (@days)
|
|
|
|
{
|
2019-05-28 18:19:42 +02:00
|
|
|
if ($date =~ m/$day/i)
|
2007-05-20 22:44:44 +02:00
|
|
|
{
|
|
|
|
$date = $i;
|
|
|
|
last;
|
|
|
|
}
|
2019-06-26 18:34:19 +02:00
|
|
|
$i = $i + 1;
|
2007-05-20 22:44:44 +02:00
|
|
|
}
|
|
|
|
|
2019-05-28 18:19:42 +02:00
|
|
|
if ($i > 4 && $date ne "")
|
2007-05-20 22:44:44 +02:00
|
|
|
{
|
|
|
|
print("\'$date\' is not a valid day, valid days for $country, $state, $city are: ",
|
|
|
|
join(" ", @days[1,2,3,4]), "\n");
|
|
|
|
die;
|
|
|
|
}
|
|
|
|
|
|
|
|
$text =~ m/Currently:/g;
|
|
|
|
$temp = $1
|
2019-05-28 18:19:42 +02:00
|
|
|
if ($text =~ m/<b>(.*?)°/g);
|
2007-05-20 22:44:44 +02:00
|
|
|
|
2019-05-28 18:19:42 +02:00
|
|
|
if ($date == 0)
|
2007-05-20 22:44:44 +02:00
|
|
|
{
|
|
|
|
$text =~ m/Arial\ssize=2>(.*?)</g;
|
|
|
|
$cond = $1
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for($i = 0; $i <= $date; $i++)
|
|
|
|
{
|
|
|
|
$text =~ m/<td\salign.*?\scolspan.*?size=2>(.*?)&/mgi;
|
|
|
|
$cond = $1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-28 18:19:42 +02:00
|
|
|
if ($cond eq "Unknown")
|
2007-05-20 22:44:44 +02:00
|
|
|
{
|
|
|
|
for($i = 0; $i <= $date; $i++)
|
|
|
|
{
|
|
|
|
$text =~ m/<td\salign.*?\scolspan.*?size=2>(.*?)&/mgi;
|
|
|
|
$cond = $1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for($i = 0; $i <= $date; $i++)
|
|
|
|
{
|
2019-06-26 18:34:19 +02:00
|
|
|
$text =~
|
2007-05-20 22:44:44 +02:00
|
|
|
m/<td\salign=right\scolspan=1.*?face=Arial>High\:.*?size=3\sface=Arial>\n\s\s(.*?)\&/sgi;
|
|
|
|
$high = $1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for($i = 0; $i <= $date; $i++)
|
|
|
|
{
|
2019-06-26 18:34:19 +02:00
|
|
|
$text =~
|
2007-05-20 22:44:44 +02:00
|
|
|
m/<td\salign=right\scolspan=1.*?face=Arial>Low\:.*?size=3\sface=Arial>\n\s(.*?)\&/sgi;
|
|
|
|
$low = $1;
|
|
|
|
}
|
|
|
|
|
2019-05-28 18:19:42 +02:00
|
|
|
if ($text =~ m/More Current Conditions<\/b>/g)
|
2007-05-20 22:44:44 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
$text =~ m/Feels Like:/g;
|
|
|
|
$feels = $1
|
2019-05-28 18:19:42 +02:00
|
|
|
if ($text =~ m/size=2>\n(.*?)°/sg);
|
2007-05-20 22:44:44 +02:00
|
|
|
|
|
|
|
$text =~ m/Wind:/g;
|
|
|
|
$wind = $1
|
2019-05-28 18:19:42 +02:00
|
|
|
if ($text =~ m/size=2>\n(.*?)</sg);
|
2007-05-20 22:44:44 +02:00
|
|
|
|
|
|
|
$wind =~ s/\n//g;
|
|
|
|
$wind =~ s/\r//g;
|
|
|
|
|
|
|
|
$text =~ m/Humidity:/g;
|
|
|
|
$humid = $1
|
2019-05-28 18:19:42 +02:00
|
|
|
if ($text =~ m/size=2>\n(.*?)\n/sg);
|
2007-05-20 22:44:44 +02:00
|
|
|
|
|
|
|
$text =~ m/Sunrise:/g;
|
|
|
|
$sunup = $1
|
2019-05-28 18:19:42 +02:00
|
|
|
if ($text =~ m/size=2>\n(.*?)</sg);
|
2007-05-20 22:44:44 +02:00
|
|
|
|
|
|
|
$text =~ m/Sunset:/g;
|
|
|
|
$sundown = $1
|
2019-05-28 18:19:42 +02:00
|
|
|
if ($text =~ m/size=2>\n(.*?)</sg);
|
2007-05-20 22:44:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$today = "Today: $1"
|
|
|
|
if $text =~ m/<b>Today:<\/b>\s(.*?)<p>/g;
|
|
|
|
|
|
|
|
$tonight = "Tonight: $1"
|
|
|
|
if $text =~ m/<b>Tonight:<\/b>\s(.*?)<p>/g;
|
|
|
|
|
|
|
|
$feelsc = int(5/9*($feels - 32));
|
|
|
|
$tempc = int(5/9*($temp - 32));
|
|
|
|
$highc = int(5/9*($high - 32));
|
|
|
|
$lowc = int(5/9*($low - 32));
|
|
|
|
|
2019-05-28 18:19:42 +02:00
|
|
|
if ($date > 0)
|
2007-05-20 22:44:44 +02:00
|
|
|
{
|
|
|
|
$date = "[".$days[$date]."] ";
|
|
|
|
}
|
|
|
|
|
|
|
|
$date =~ s/Mon/Monday/i;
|
|
|
|
$date =~ s/Tue/Tuesday/i;
|
|
|
|
$date =~ s/Wed/Wednesday/i;
|
|
|
|
$date =~ s/Thu/Thursday/i;
|
|
|
|
$date =~ s/Fri/Friday/i;
|
|
|
|
$date =~ s/Sat/Saturday/i;
|
|
|
|
$date =~ s/Sun/Sunday/i;
|
|
|
|
|
|
|
|
|
2019-05-28 18:19:42 +02:00
|
|
|
if ($date eq "")
|
2007-05-20 22:44:44 +02:00
|
|
|
{
|
|
|
|
print "$country, $state, $city (Updated $update): Temp: ".$temp."F/".$tempc."C (Feels like: $feels"."F/".$feelsc."C), ".
|
|
|
|
"High: ".$high."F/".$highc."C, Low: ".$low."F/".$lowc."C, ".
|
|
|
|
"Sky: $cond, Humidity: $humid, Wind: $wind, Sunrise: $sunup, Sunset: $sundown, $today $tonight\n";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
print "$country, $state, $city (Updated $update): $date".
|
|
|
|
"High: ".$high."F/".$highc."C, Low: ".$low."F/".$lowc."C, ".
|
|
|
|
"Sky: $cond.\n";
|
|
|
|
}
|