daily pastebin goal
43%
SHARE
TWEET

Untitled

a guest Mar 13th, 2018 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use Geo::WeatherNWS;
  2. use Weather::Underground;
  3. use Data::Dumper;
  4. use Geo::IATA;
  5. use List::AllUtils qw/first/;
  6. use Text::Levenshtein qw/fastdistance/;
  7.  
  8. # Stefan Petrea
  9. # stefan.petrea at gmail.com
  10. # perlhobby.googlecode.com
  11.  
  12. use Text::Levenshtein qw/fastdistance/;
  13.  
  14.  
  15. sub solve_weather {
  16.     my $arg = shift;
  17.     my $g = Geo::IATA->new;
  18.     my $location =
  19.     first { defined $_->{icao} }
  20.         @{$g->location($arg)};
  21.     my $weather = Weather::Underground->new( place => $location->{icao}, debug => 0 );
  22.  
  23.  
  24.     my $data = undef;
  25.     eval{ my $data = $weather->get_weather; };
  26.     if(!defined($data)) {
  27.         my $min="999999999";
  28.         my $match = undef;
  29.  
  30.         for( @{ $g->location('%') } ) {
  31.             $dist = fastdistance($_->{location},$arg);
  32.             if($dist < 10 && $dist < $min) {
  33.                 $min   = $dist;
  34.                 $match  = $_;
  35.                 $dist == 1 && last;
  36.             };
  37.         }
  38.         $weather = Weather::Underground->new( place => $match->{icao}, debug => 0 );
  39.         $location = $match;
  40.     };
  41.  
  42.     return ($weather,$data,$location->{location});
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top