Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use Geo::WeatherNWS;
- use Weather::Underground;
- use Data::Dumper;
- use Geo::IATA;
- use List::AllUtils qw/first/;
- use Text::Levenshtein qw/fastdistance/;
- # Stefan Petrea
- # stefan.petrea at gmail.com
- # perlhobby.googlecode.com
- use Text::Levenshtein qw/fastdistance/;
- sub solve_weather {
- my $arg = shift;
- my $g = Geo::IATA->new;
- my $location =
- first { defined $_->{icao} }
- @{$g->location($arg)};
- my $weather = Weather::Underground->new( place => $location->{icao}, debug => 0 );
- my $data = undef;
- eval{ my $data = $weather->get_weather; };
- if(!defined($data)) {
- my $min="999999999";
- my $match = undef;
- for( @{ $g->location('%') } ) {
- $dist = fastdistance($_->{location},$arg);
- if($dist < 10 && $dist < $min) {
- $min = $dist;
- $match = $_;
- $dist == 1 && last;
- };
- }
- $weather = Weather::Underground->new( place => $match->{icao}, debug => 0 );
- $location = $match;
- };
- return ($weather,$data,$location->{location});
- }
Add Comment
Please, Sign In to add comment