2007-05-20 22:44:44 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
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, $buffer, $location);
|
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
if ($#ARGV < 0) {
|
|
|
|
print "Try again. Please specify the location you would like to search for nearby cities around.\n";
|
|
|
|
die;
|
2007-05-20 22:44:44 +02:00
|
|
|
}
|
2019-06-26 18:34:19 +02:00
|
|
|
|
2007-05-20 22:44:44 +02:00
|
|
|
$location = join("+", @ARGV);
|
|
|
|
|
|
|
|
$location =~ s/,/%2C/;
|
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
if ($location =~ m/\+-(.*)/) {
|
|
|
|
|
|
|
|
# -arguments?
|
|
|
|
$location =~ s/\+-.*//;
|
2007-05-20 22:44:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$text = get("http://weather.yahoo.com/search/weather2?p=$location");
|
|
|
|
|
|
|
|
$location =~ s/\+/ /g;
|
|
|
|
$location =~ s/%2C/,/g;
|
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
if ($text =~ m/No match found/) {
|
|
|
|
print "$location is not a valid location for this service.\n";
|
|
|
|
die;
|
2007-05-20 22:44:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
my $found = 0;
|
|
|
|
my $buf;
|
|
|
|
my $i;
|
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
if ($text =~ m/location matches\:/g) {
|
|
|
|
$buf = "Multiple locations found: ";
|
2007-05-20 22:44:44 +02:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
while ($text =~ m/<a\shref="\/forecast\/(.*?)">(.*?)<\/a>/g) {
|
|
|
|
$i = $1;
|
|
|
|
$buffer = $2;
|
2007-05-20 22:44:44 +02:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
$buffer =~ s/<b>//g;
|
|
|
|
$buffer =~ s/<\/b>//g;
|
|
|
|
$buffer =~ s/^\s+//;
|
2007-05-20 22:44:44 +02:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
$buf = $buf . "$buffer - ";
|
2007-05-20 22:44:44 +02:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
if ($location =~ m/$buffer/i) {
|
|
|
|
$text = get("http://weather.yahoo.com/forecast/$i");
|
|
|
|
$found = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$buf = $buf . "please specify one of these.\n";
|
|
|
|
if (not $found) {
|
|
|
|
print $buf;
|
|
|
|
die;
|
2007-05-20 22:44:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
my ($country, $state, $city);
|
2007-05-20 22:44:44 +02:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
$text =~ m/<a href="\/">Weather<\/a>\s>/g;
|
|
|
|
$text =~ m/<a href=.*?>(.*?)<\/a>\s>/g;
|
|
|
|
$country = $1;
|
2007-05-20 22:44:44 +02:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
if ($country eq "North America") {
|
2007-05-20 22:44:44 +02:00
|
|
|
$text =~ m/<a href=.*?>(.*?)<\/a>\s>/g;
|
|
|
|
$country = $1;
|
2020-02-15 23:38:32 +01:00
|
|
|
}
|
2007-05-20 22:44:44 +02:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
if ($country ne "Canada") {
|
2007-05-20 22:44:44 +02:00
|
|
|
$text =~ m/<a href=.*?>(.*?)<\/a>\s>/g;
|
|
|
|
$state = $1;
|
2020-02-15 23:38:32 +01:00
|
|
|
}
|
2007-05-20 22:44:44 +02:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
$text =~ m/^(.*?)<\/b><\/font>/mg;
|
|
|
|
$city = $1;
|
2007-05-20 22:44:44 +02:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
$text =~ m/Nearby.*?Locations/sgi;
|
2007-05-20 22:44:44 +02:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
print "$country, $state, $city - Nearby Locations: ";
|
2007-05-20 22:44:44 +02:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
while ($text =~ m/<a href=\"\/forecast\/.*?\.html\">(.*?)<\/a>/gi) {
|
2007-05-20 22:44:44 +02:00
|
|
|
$buf = $1;
|
|
|
|
$buf =~ s/<.*?>//gi;
|
|
|
|
print "$buf, ";
|
2020-02-15 23:38:32 +01:00
|
|
|
}
|
|
|
|
print "\n";
|