| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package WWW::GoKGS::Scraper::TournGames; |
|
2
|
9
|
|
|
9
|
|
7299
|
use strict; |
|
|
9
|
|
|
|
|
21
|
|
|
|
9
|
|
|
|
|
399
|
|
|
3
|
9
|
|
|
9
|
|
50
|
use warnings; |
|
|
9
|
|
|
|
|
19
|
|
|
|
9
|
|
|
|
|
910
|
|
|
4
|
9
|
|
|
9
|
|
48
|
use parent qw/WWW::GoKGS::Scraper/; |
|
|
9
|
|
|
|
|
21
|
|
|
|
9
|
|
|
|
|
60
|
|
|
5
|
9
|
|
|
9
|
|
558
|
use WWW::GoKGS::Scraper::Declare; |
|
|
9
|
|
|
|
|
19
|
|
|
|
9
|
|
|
|
|
75
|
|
|
6
|
9
|
|
|
9
|
|
604
|
use WWW::GoKGS::Scraper::Filters qw/datetime game_result/; |
|
|
9
|
|
|
|
|
21
|
|
|
|
9
|
|
|
|
|
577
|
|
|
7
|
9
|
|
|
9
|
|
63
|
use WWW::GoKGS::Scraper::TournLinks; |
|
|
9
|
|
|
|
|
37
|
|
|
|
9
|
|
|
|
|
8061
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
10
|
|
|
10
|
1
|
50
|
sub base_uri { 'http://www.gokgs.com/tournGames.jsp' } |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub __build_scraper { |
|
12
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
|
13
|
1
|
|
|
|
|
4
|
my $links = $self->__build_tourn_links; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my %h1 = ( |
|
16
|
0
|
|
|
0
|
|
0
|
name => [ 'TEXT', sub { s/ Round \d+ Games$// } ], |
|
17
|
1
|
0
|
|
0
|
|
17
|
round => [ 'TEXT', sub { m/ Round (\d+) Games$/ && $1 } ], |
|
|
0
|
|
|
|
|
0
|
|
|
18
|
|
|
|
|
|
|
); |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my %player = ( |
|
21
|
0
|
|
|
0
|
|
0
|
name => [ 'TEXT', sub { s/ \[[^\]]+\]$// } ], |
|
22
|
1
|
0
|
|
0
|
|
6
|
rank => [ 'TEXT', sub { m/ \[([^\]]+)\]$/ && $1 } ], |
|
|
0
|
|
|
|
|
0
|
|
|
23
|
|
|
|
|
|
|
); |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $game = scraper { |
|
26
|
0
|
|
|
0
|
|
0
|
process '//td[1]/a', 'sgf_uri' => '@href'; |
|
27
|
0
|
|
|
|
|
0
|
process '//td[2]', 'white' => \%player; |
|
28
|
0
|
|
|
|
|
0
|
process '//td[3]', 'black' => \%player, |
|
29
|
|
|
|
|
|
|
'maybe_bye' => 'TEXT'; |
|
30
|
0
|
|
|
|
|
0
|
process '//td[4]', 'setup' => 'TEXT'; |
|
31
|
0
|
|
|
|
|
0
|
process '//td[5]', 'start_time' => [ 'TEXT', \&datetime ]; |
|
32
|
0
|
|
|
|
|
0
|
process '//td[6]', 'result' => [ 'TEXT', \&game_result ]; |
|
33
|
1
|
|
|
|
|
6
|
}; |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
scraper { |
|
36
|
0
|
|
|
0
|
|
|
process '//h1', %h1; |
|
37
|
0
|
|
|
|
|
|
process '//a[@href="tzList.jsp"]', 'time_zone' => 'TEXT'; |
|
38
|
0
|
|
|
|
|
|
process '//table[@class="grid"]//following-sibling::tr', |
|
39
|
|
|
|
|
|
|
'games[]' => $game; |
|
40
|
0
|
|
|
|
|
|
process '//a[text()="Previous round"]', 'previous_round_uri' => '@href'; |
|
41
|
0
|
|
|
|
|
|
process '//a[text()="Next round"]', 'next_round_uri' => '@href'; |
|
42
|
0
|
|
|
|
|
|
process '//div[@class="tournData"]', 'links' => $links; |
|
43
|
1
|
|
|
|
|
10
|
}; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub scrape { |
|
47
|
0
|
|
|
0
|
1
|
|
my ( $self, @args ) = @_; |
|
48
|
0
|
|
|
|
|
|
my $result = $self->SUPER::scrape( @args ); |
|
49
|
|
|
|
|
|
|
|
|
50
|
0
|
0
|
|
|
|
|
return $result unless $result->{games}; |
|
51
|
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
my ( @games, @byes ); |
|
53
|
0
|
|
|
|
|
|
for my $game ( @{$result->{games}} ) { |
|
|
0
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
my $maybe_bye = delete $game->{maybe_bye}; |
|
55
|
0
|
0
|
|
|
|
|
if ( $maybe_bye =~ /^Bye(?: \(([^\)]+)\))?$/ ) { |
|
56
|
0
|
|
|
|
|
|
push @byes, { |
|
57
|
|
|
|
|
|
|
type => $1 || 'System', |
|
58
|
0
|
|
0
|
|
|
|
%{$game->{white}}, |
|
59
|
|
|
|
|
|
|
}; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
else { |
|
62
|
0
|
|
|
|
|
|
push @games, $game; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
for my $game ( @games ) { |
|
67
|
0
|
|
|
|
|
|
$game->{setup} =~ /^(\d+)\x{d7}\d+ (?:H(\d+))?$/; |
|
68
|
0
|
|
|
|
|
|
$game->{board_size} = $1; |
|
69
|
0
|
0
|
|
|
|
|
$game->{handicap} = $2 if defined $2; |
|
70
|
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
delete $game->{setup}; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
delete $result->{games}; |
|
75
|
|
|
|
|
|
|
|
|
76
|
0
|
0
|
|
|
|
|
$result->{byes} = \@byes if @byes; |
|
77
|
0
|
0
|
|
|
|
|
$result->{games} = \@games if @games; |
|
78
|
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
$result; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
__END__ |