line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Acme::MobileTradeFun::NewParser; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
49
|
|
5
|
1
|
|
|
1
|
|
804
|
use Mojo::DOM; |
|
1
|
|
|
|
|
60096
|
|
|
1
|
|
|
|
|
37
|
|
6
|
1
|
|
|
1
|
|
10
|
use Log::Log4perl qw/:easy/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
11
|
|
7
|
1
|
|
|
1
|
|
1511
|
use URI::Encode qw/uri_decode/; |
|
1
|
|
|
|
|
1241
|
|
|
1
|
|
|
|
|
65
|
|
8
|
1
|
|
|
1
|
|
450
|
use Acme::MobileTradeFun::Utils; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
20
|
|
9
|
1
|
|
|
1
|
|
5
|
use Data::Dumper; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
421
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
0
|
|
|
0
|
0
|
|
my ( $class, $args ) = @_; |
13
|
0
|
|
|
|
|
|
my $self = {}; |
14
|
0
|
|
|
|
|
|
$self->{ utils } = Acme::MobileTradeFun::Utils->new(); |
15
|
0
|
|
|
|
|
|
return bless $self, $class; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head2 parse_data |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
parses HTML, populates $self->{ data } hash |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=cut |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub parse_data { |
25
|
0
|
|
|
0
|
1
|
|
my ( $self, $html, $all_cards ) = @_; |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
my $card_found = 0; |
28
|
0
|
|
|
|
|
|
my $dom = Mojo::DOM->new( $html ); |
29
|
0
|
|
|
|
|
|
my @new_cards; |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
for my $card ( $dom->find( 'section.card' )->each ) { |
32
|
0
|
|
|
|
|
|
my $category = ( $card->find( 'span' )->each )[0]->text; |
33
|
0
|
|
|
|
|
|
my @links = $card->find( 'a' )->each; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
my $name = $links[1]->text; |
36
|
0
|
|
|
|
|
|
my $rarity = $links[2]->text; |
37
|
0
|
|
|
|
|
|
$rarity =~ s/\(//; |
38
|
0
|
|
|
|
|
|
$rarity =~ s/\)//; |
39
|
0
|
|
|
|
|
|
my $link = $links[3]->attr( 'href' ); |
40
|
|
|
|
|
|
|
|
41
|
0
|
0
|
0
|
|
|
|
unless ( $category && $name && $rarity && $link ) { |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
42
|
0
|
|
|
|
|
|
my $message = "Something is missing:"; |
43
|
0
|
0
|
|
|
|
|
$message .= " $category" if ( $category ); |
44
|
0
|
0
|
|
|
|
|
$message .= " $name" if ( $name ); |
45
|
0
|
0
|
|
|
|
|
$message .= " $rarity" if ( $rarity ); |
46
|
0
|
0
|
|
|
|
|
$message .= " $link" if ( $link ); |
47
|
0
|
|
|
|
|
|
DEBUG $message; |
48
|
0
|
|
|
|
|
|
next; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
my $url = uri_decode( $link ); |
52
|
0
|
|
|
|
|
|
my $card_name = "[$category]$name($rarity).jpg"; |
53
|
0
|
|
|
|
|
|
$card_name =~ s/\s+//g; # sometimes bunch of spaces creep in |
54
|
0
|
|
|
|
|
|
$card_found++; |
55
|
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
|
if ( $self->{ utils }->is_new_card( $card_name, $all_cards ) ) { |
57
|
0
|
|
|
|
|
|
my $elem = { name => $card_name, url => $url }; |
58
|
0
|
|
|
|
|
|
push @new_cards, $elem; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
0
|
|
|
|
|
|
return ( $card_found, @new_cards ); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |