| 1 | package WWW::GoKGS::Scraper::GameArchives; | ||||||||||||||||||||||||||||
| 2 | 15 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 15 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 15 | ▶ | use parent qw/WWW::GoKGS::Scraper/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 15 | ▶ | use WWW::GoKGS::Scraper::Declare; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 15 | ▶ | use WWW::GoKGS::Scraper::Filters qw/game_result datetime/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 16 | ▶ | sub base_uri { 'http://www.gokgs.com/gameArchives.jsp' } | ||||||||||||||||||||||||||
|
Subroutine
base_uri: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | sub __build_scraper { | ||||||||||||||||||||||||||
|
Subroutine
__build_scraper: called CC=1 SCAR=2.9
| |||||||||||||||||||||||||||||
| 11 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | my $month2num = do { | |||||||||||||||||||||||||||
| 14 | 1 | my @months = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ); | |||||||||||||||||||||||||||
| 15 | 1 | my %month2num; @month2num{ @months } = ( 1..12 ); | |||||||||||||||||||||||||||
| 16 | 0 | ▶ | sub { $month2num{$_[0]} }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 17 | }; | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | my %user = ( | ||||||||||||||||||||||||||||
| 20 | 0 | ▶ | name => [ 'TEXT', sub { s/ \[[^\]]+\]$// } ], | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 21 | 0 | ▶ | rank => [ 'TEXT', sub { m/ \[([^\]]+)\]$/ ? $1 : undef } ], | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | uri => '@href', | ||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 0 | ▶ | my $game = scraper { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 26 | 0 | process '//td[1]/a', 'sgf_uri' => '@href'; | |||||||||||||||||||||||||||
| 27 | 0 | process '//td[2]/a', 'white[]' => \%user; | |||||||||||||||||||||||||||
| 28 | 0 | process '//td[3]/a', 'black[]' => \%user; | |||||||||||||||||||||||||||
| 29 | 0 | process '//td[3]', 'maybe_setup' => 'TEXT'; | |||||||||||||||||||||||||||
| 30 | 0 | process '//td[4]', 'setup' => 'TEXT'; | |||||||||||||||||||||||||||
| 31 | 0 | process '//td[5]', 'start_time' => 'TEXT'; | |||||||||||||||||||||||||||
| 32 | 0 | process '//td[6]', 'type' => 'TEXT'; | |||||||||||||||||||||||||||
| 33 | 0 | process '//td[7]', 'result' => 'TEXT'; | |||||||||||||||||||||||||||
| 34 | 0 | process '//td[8]', 'tag' => 'TEXT'; | |||||||||||||||||||||||||||
| 35 | 1 | }; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | my $calendar = scraper { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 38 | 0 | process 'td', 'year' => 'TEXT'; | |||||||||||||||||||||||||||
| 39 | process '//following-sibling::td[not(@colspan)]', | ||||||||||||||||||||||||||||
| 40 | 0 | ▶ | 'month[]' => scraper { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 41 | 0 | process '.', 'month' => [ 'TEXT', $month2num ]; | |||||||||||||||||||||||||||
| 42 | 0 | process 'a', 'uri' => '@href'; }; | |||||||||||||||||||||||||||
| 43 | 1 | }; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | scraper { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 46 | 0 | process '//a[@href="tzList.jsp"]', 'time_zone' => 'TEXT'; | |||||||||||||||||||||||||||
| 47 | 0 | process '//table[tr/th/text()="Viewable?"]//following-sibling::tr', | |||||||||||||||||||||||||||
| 48 | 'games[]' => $game; | ||||||||||||||||||||||||||||
| 49 | 0 | process '//a[contains(@href, ".zip")]', 'zip_uri' => '@href'; | |||||||||||||||||||||||||||
| 50 | 0 | process '//a[contains(@href, ".tar.gz")]', 'tgz_uri' => '@href'; | |||||||||||||||||||||||||||
| 51 | 0 | process '//table[colgroup]//following-sibling::tr', | |||||||||||||||||||||||||||
| 52 | 'calendar[]' => $calendar; | ||||||||||||||||||||||||||||
| 53 | 1 | }; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub scrape { | ||||||||||||||||||||||||||
|
Subroutine
scrape: not called CC=19 SCAR=59.4
Pod
documented
| |||||||||||||||||||||||||||||
| 57 | 0 | my ( $self, @args ) = @_; | |||||||||||||||||||||||||||
| 58 | 0 | my $result = $self->SUPER::scrape( @args ); | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | return $result unless $result->{calendar}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | my @calendar; | |||||||||||||||||||||||||||
| 63 | 0 | for my $calendar ( @{$result->{calendar}} ) { | |||||||||||||||||||||||||||
| 64 | 0 | for my $month ( @{$calendar->{month}} ) { | |||||||||||||||||||||||||||
| 65 | 0 | $month->{year} = $calendar->{year}; | |||||||||||||||||||||||||||
| 66 | 0 | push @calendar, $month; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | ▶ | if ( @calendar == 1 and $calendar[0]{year} == 1970 ) { # KGS's bug | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@calendar == 1 and $calendar[0]{"year"} == 1970
MC/DC0%0/2
@calendar == 1 and $calendar[0]{"year"} == 1970
@calendar == 1
$calendar[0]{"year"} == 1970
Truth table0%0/3
A and B
A= @calendar == 1B= $calendar[0]{"year"} == 1970
| |||||||||||||||||||||||||||||
| 71 | 0 | delete $result->{calendar}; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | else { | ||||||||||||||||||||||||||||
| 74 | 0 | $result->{calendar} = \@calendar; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | return $result unless $result->{games}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | for my $game ( @{$result->{games}} ) { | |||||||||||||||||||||||||||
| 80 | 0 | ▶ | next if exists $game->{black}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | # <td colspan="2"> | ||||||||||||||||||||||||||||
| 83 | 0 | my $users = $game->{white}; | |||||||||||||||||||||||||||
| 84 | 0 | ▶ | if ( @$users == 1 ) { # Type: Demonstration | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 85 | 0 | $game->{owner} = $users->[0]; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | elsif ( @$users == 3 ) { # Type: Review | ||||||||||||||||||||||||||||
| 88 | 0 | $game->{owner} = $users->[0]; | |||||||||||||||||||||||||||
| 89 | 0 | $game->{white} = [ $users->[1] ]; | |||||||||||||||||||||||||||
| 90 | 0 | $game->{black} = [ $users->[2] ]; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | elsif ( @$users == 5 ) { # Type: Rengo Review | ||||||||||||||||||||||||||||
| 93 | 0 | $game->{owner} = $users->[0]; | |||||||||||||||||||||||||||
| 94 | 0 | $game->{white} = [ @{$users}[1,2] ]; | |||||||||||||||||||||||||||
| 95 | 0 | $game->{black} = [ @{$users}[3,4] ]; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | else { | ||||||||||||||||||||||||||||
| 98 | 0 | die 'Oops! Something went wrong'; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | $game->{tag} = $game->{result} if exists $game->{result}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 0 | $game->{result} = $game->{type}; | |||||||||||||||||||||||||||
| 103 | 0 | $game->{type} = $game->{start_time}; | |||||||||||||||||||||||||||
| 104 | 0 | $game->{start_time} = $game->{setup}; | |||||||||||||||||||||||||||
| 105 | 0 | $game->{setup} = $game->{maybe_setup}; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | continue { | ||||||||||||||||||||||||||||
| 108 | 0 | $game->{start_time} = datetime( $game->{start_time} ); | |||||||||||||||||||||||||||
| 109 | 0 | $game->{result} = game_result( $game->{result} ); | |||||||||||||||||||||||||||
| 110 | 0 | $game->{setup} =~ /^(\d+)\x{d7}\d+ (?:H(\d+))?$/; | |||||||||||||||||||||||||||
| 111 | 0 | $game->{board_size} = $1; | |||||||||||||||||||||||||||
| 112 | 0 | ▶ | $game->{handicap} = $2 if defined $2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | for my $user ( | ||||||||||||||||||||||||||
|
Condition0%0/3
$game->{'owner'} || ()
MC/DC0%0/2
$game->{'owner'} || ()
$game->{'owner'}
()
Truth table0%0/3
A || B
A= $game->{'owner'}B= ()
| |||||||||||||||||||||||||||||
| 115 | $game->{owner} || (), | ||||||||||||||||||||||||||||
| 116 | 0 | ▶ | @{ $game->{black} || [] }, | ||||||||||||||||||||||||||
|
Condition0%0/2
$game->{'black'} || []
MC/DC0%0/1
$game->{'black'} || []
$game->{'black'}
Truth table0%0/2
A
A= $game->{'black'}
| |||||||||||||||||||||||||||||
| 117 | 0 | ▶ | @{ $game->{white} || [] }, | ||||||||||||||||||||||||||
|
Condition0%0/2
$game->{'white'} || []
MC/DC0%0/1
$game->{'white'} || []
$game->{'white'}
Truth table0%0/2
A
A= $game->{'white'}
| |||||||||||||||||||||||||||||
| 118 | ) { | ||||||||||||||||||||||||||||
| 119 | 0 | ▶ | delete $user->{rank} unless $user->{rank}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 0 | delete $game->{setup}; | |||||||||||||||||||||||||||
| 123 | 0 | delete $game->{maybe_setup}; | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 0 | $result; | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 15 | 1; | |||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | __END__ | ||||||||||||||||||||||||||||