Guest User

Untitled

a guest
Mar 13th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  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. }
Add Comment
Please, Sign In to add comment