line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package POE::Component::IRC::Plugin::WWW::Weather::US; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
30056
|
use 5.010; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
122
|
|
4
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
36
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
145
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
1424
|
use POE::Component::IRC::Plugin qw( :ALL ); |
|
1
|
|
|
|
|
725
|
|
|
1
|
|
|
|
|
175
|
|
8
|
1
|
|
|
1
|
|
1108
|
use Mojo::UserAgent; |
|
1
|
|
|
|
|
383414
|
|
|
1
|
|
|
|
|
14
|
|
9
|
1
|
|
|
1
|
|
982
|
use Cache::Memory::Simple; |
|
1
|
|
|
|
|
753
|
|
|
1
|
|
|
|
|
447
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
15
|
0
|
|
|
|
|
|
my $self = bless { |
16
|
|
|
|
|
|
|
cache => Cache::Memory::Simple->new, |
17
|
|
|
|
|
|
|
}, $class; |
18
|
0
|
|
|
|
|
|
return $self; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub PCI_register { |
22
|
0
|
|
|
0
|
0
|
|
my ($self, $irc) = splice @_, 0, 2; |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
$irc->plugin_register($self, 'SERVER', qw(public)); |
25
|
0
|
|
|
|
|
|
return 1; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# This is method is mandatory but we don't actually have anything to do. |
29
|
|
|
|
|
|
|
sub PCI_unregister { |
30
|
0
|
|
|
0
|
0
|
|
return 1; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub S_public { |
34
|
0
|
|
|
0
|
0
|
|
my ($self, $irc) = splice @_, 0, 2; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Parameters are passed as scalar-refs including arrayrefs. |
37
|
0
|
|
|
|
|
|
my $nick = (split /!/, ${$_[0]})[0]; |
|
0
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
my $channel = ${$_[1]}->[0]; |
|
0
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my $msg = ${$_[2]}; |
|
0
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
0
|
0
|
|
|
|
|
if (my ($zip) = $msg =~ /^!weather\s+(\d{5})/i) { |
42
|
0
|
|
|
|
|
|
my $reply = $self->_get_weather($zip); |
43
|
0
|
0
|
|
|
|
|
$irc->yield(privmsg => $channel => "$nick: $reply") if $reply; |
44
|
0
|
|
|
|
|
|
return PCI_EAT_PLUGIN; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# Default action is to allow other plugins to process it. |
48
|
0
|
|
|
|
|
|
return PCI_EAT_NONE; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# the link I use for zip redirects, so set max_redirects to 1 |
52
|
|
|
|
|
|
|
sub _get_weather { |
53
|
0
|
0
|
|
0
|
|
|
my ($self, $zip) = @_ or return; |
54
|
0
|
|
|
|
|
|
$self->{cache}->purge(); # purge any expired items |
55
|
|
|
|
|
|
|
return $self->{cache}->get_or_set( |
56
|
|
|
|
|
|
|
$zip, |
57
|
|
|
|
|
|
|
sub { |
58
|
|
|
|
|
|
|
Mojo::UserAgent->new->max_redirects(1) |
59
|
|
|
|
|
|
|
->get("http://forecast.weather.gov/zipcity.php?inputstring=$zip") |
60
|
|
|
|
|
|
|
->res->dom->find('.point-forecast-7-day .row-odd') |
61
|
0
|
|
|
0
|
|
|
->map(sub { $_->find('span')->pluck('text') . ': ' . $_->text })->[0]; |
|
0
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
}, |
63
|
0
|
|
|
|
|
|
3600 # cache for 1 hour |
64
|
|
|
|
|
|
|
); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |
68
|
|
|
|
|
|
|
__END__ |