| 1 | package Bot::IRC::X::MetarTaf; | ||||||||||
| 2 | # ABSTRACT: Bot::IRC plugin for METAR and TAF reporting | ||||||||||
| 3 | |||||||||||
| 4 | 2 | ▶ | use 5.016; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use exact; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 2 | ▶ | use LWP::Simple 'get'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 2 | our $VERSION = '1.07'; # VERSION | |||||||||
| 10 | |||||||||||
| 11 | 1 | ▶ | sub init { | ||||||||
|
Subroutine
init: called CC=1 SCAR=5.3
Pod
undocumented
| |||||||||||
| 12 | 1 | my ($bot) = @_; | |||||||||
| 13 | |||||||||||
| 14 | $bot->hook( | ||||||||||
| 15 | { | ||||||||||
| 16 | to_me => 1, | ||||||||||
| 17 | text => qr/^(?<type>metar|taf)\s+(?<code>\S+)/i, | ||||||||||
| 18 | }, | ||||||||||
| 19 | 0 | ▶ | sub { | ||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=37.4
| |||||||||||
| 20 | 0 | my ( $bot, $in, $m ) = @_; | |||||||||
| 21 | 0 | my $code = uc( $m->{code} ); | |||||||||
| 22 | 0 | ▶ | $code = 'K' . $code if ( length $code == 3 ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | |||||||||||
| 24 | 0 | ▶ | if ( lc( $m->{type} ) eq 'taf' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | 0 | my $content = get( | |||||||||
| 26 | 'http://tgftp.nws.noaa.gov/data/forecasts/taf/stations/' . $code . '.TXT', | ||||||||||
| 27 | ); | ||||||||||
| 28 | |||||||||||
| 29 | 0 | ▶ | if ($content) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | 0 | my @content = split( /\r?\n/, $content ); | |||||||||
| 31 | 0 | shift @content for ( 0 .. 1 ); | |||||||||
| 32 | 0 | $bot->reply_to( join( '; ', map { s/^\s+|\s+$//g; $_ } @content ) ); | |||||||||
| 33 | } | ||||||||||
| 34 | else { | ||||||||||
| 35 | 0 | $bot->reply_to("Unable to find TAF data for $code."); | |||||||||
| 36 | } | ||||||||||
| 37 | } | ||||||||||
| 38 | else { | ||||||||||
| 39 | 0 | my $content = get( | |||||||||
| 40 | 'http://tgftp.nws.noaa.gov/data/observations/metar/stations/' . $code . '.TXT', | ||||||||||
| 41 | ); | ||||||||||
| 42 | 0 | ▶ | if ($content) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | 0 | $bot->reply_to( ( split( /\r?\n/, $content ) )[1] ); | |||||||||
| 44 | } | ||||||||||
| 45 | else { | ||||||||||
| 46 | 0 | $bot->reply_to("Unable to find METAR data for $code."); | |||||||||
| 47 | } | ||||||||||
| 48 | } | ||||||||||
| 49 | }, | ||||||||||
| 50 | 1 | ); | |||||||||
| 51 | |||||||||||
| 52 | 1 | $bot->helps( | |||||||||
| 53 | metartaf => | ||||||||||
| 54 | 'Get airport weather from NOAA. ' . | ||||||||||
| 55 | 'Usage: <bot> metar <airport code>; <bot> taf <airport code>.', | ||||||||||
| 56 | ); | ||||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | 2 | 1; | |||||||||
| 60 | |||||||||||
| 61 | __END__ | ||||||||||