Révision e6f3dae6
| b/fftt2datas.pl | ||
|---|---|---|
| 1 |
#!/usr/bin/perl -w |
|
| 2 |
use strict; |
|
| 3 |
use warnings; |
|
| 4 |
|
|
| 5 |
use Data::Dumper; |
|
| 6 |
use HTML::Parser; |
|
| 7 |
|
|
| 8 |
my @lstEquipes; |
|
| 9 |
my @lstJournees; |
|
| 10 |
my %matchs; |
|
| 11 |
|
|
| 12 |
sub searchEquipe {
|
|
| 13 |
my $equipe = shift; |
|
| 14 |
my $i; |
|
| 15 |
|
|
| 16 |
if ($equipe && $#lstEquipes) {
|
|
| 17 |
for ($i = 0; $i < $#lstEquipes; $i++) {
|
|
| 18 |
last if ($lstEquipes[$i] eq $equipe); |
|
| 19 |
} |
|
| 20 |
} |
|
| 21 |
|
|
| 22 |
return ((defined($i) && $lstEquipes[$i] eq $equipe) ? $i : undef); |
|
| 23 |
} |
|
| 24 |
|
|
| 25 |
{
|
|
| 26 |
my ($nomClub, $col, $journee, $stateJournees) = (0, 0, 0, 0); |
|
| 27 |
my ($e1, $e2, $resu1, $resu2); |
|
| 28 |
sub start {
|
|
| 29 |
my ($tag, $attr) = @_; |
|
| 30 |
#print "START=$tag\n"; |
|
| 31 |
#while( my ($k, $v) = each %$attr ) {
|
|
| 32 |
# print "<$tag> key: $k, value: $v.\n"; |
|
| 33 |
#} |
|
| 34 |
} |
|
| 35 |
|
|
| 36 |
sub end {
|
|
| 37 |
my ($tag) = @_; |
|
| 38 |
#print "END=$tag\n"; |
|
| 39 |
} |
|
| 40 |
|
|
| 41 |
sub text {
|
|
| 42 |
my ($text) = @_; |
|
| 43 |
#print "TEXT=$text\n"; |
|
| 44 |
$nomClub = 1 if ($text eq 'Equipe'); |
|
| 45 |
$col = ($col + 1) % 10 if ($nomClub == 1 && $text !~ /\s*\r*\n+/); |
|
| 46 |
if ($col == 1 && $text ne 'Equipe') {
|
|
| 47 |
$text =~ s/\xA0(.*)$/$1/; # suppression de l'espace insécable |
|
| 48 |
$text = 'Exempt' if ($text eq '0'); |
|
| 49 |
print "equipe=$text\n"; |
|
| 50 |
push(@lstEquipes, $text); |
|
| 51 |
} |
|
| 52 |
if ($text =~ /Poule.* - .*n° (\d+) - du (..\/..\/..)/) {
|
|
| 53 |
$nomClub = 0; |
|
| 54 |
$journee = $1; |
|
| 55 |
print "journee $1 du $2\n"; |
|
| 56 |
push(@lstJournees, $2); |
|
| 57 |
$stateJournees = 1; |
|
| 58 |
} else {
|
|
| 59 |
if ($stateJournees == 1) {
|
|
| 60 |
if (defined($e1 = searchEquipe($text))) {
|
|
| 61 |
$stateJournees = 2; |
|
| 62 |
} |
|
| 63 |
} elsif ($stateJournees == 2) {
|
|
| 64 |
if (defined($e2 = searchEquipe($text))) {
|
|
| 65 |
$stateJournees = 3; |
|
| 66 |
} |
|
| 67 |
} elsif ($stateJournees == 3) {
|
|
| 68 |
$resu1 = $text; |
|
| 69 |
$stateJournees = 4; |
|
| 70 |
} elsif ($stateJournees == 4) {
|
|
| 71 |
my ($score1, $score2); |
|
| 72 |
$resu2 = $text; |
|
| 73 |
if ($resu1 =~ /\d+/ && $resu2 =~ /\d+/) {
|
|
| 74 |
if ($resu1 > $resu2) {
|
|
| 75 |
$score1 = 3; |
|
| 76 |
$score2 = 1; |
|
| 77 |
} elsif ($resu1 < $resu2) {
|
|
| 78 |
$score1 = 1; |
|
| 79 |
$score2 = 3; |
|
| 80 |
} else {
|
|
| 81 |
$score1 = 2; |
|
| 82 |
$score2 = 2; |
|
| 83 |
} |
|
| 84 |
} else {
|
|
| 85 |
$resu1 = ""; |
|
| 86 |
$resu2 = ""; |
|
| 87 |
$score1 = ""; |
|
| 88 |
$score2 = ""; |
|
| 89 |
} |
|
| 90 |
$matchs{$journee-1}{$e1.'-'.$e2} = "$resu1:$resu2:$score1:$score2".'::';
|
|
| 91 |
$stateJournees = 1; |
|
| 92 |
} |
|
| 93 |
} |
|
| 94 |
} |
|
| 95 |
} |
|
| 96 |
|
|
| 97 |
my $parser = HTML::Parser->new(); |
|
| 98 |
|
|
| 99 |
# définition des mes evenements |
|
| 100 |
$parser->handler( text => \&text, "dtext" ); |
|
| 101 |
$parser->handler( start => \&start, "tagname,attr" ); |
|
| 102 |
$parser->handler( end => \&end, "tagname" ); |
|
| 103 |
|
|
| 104 |
my $html = join('', <STDIN>);
|
|
| 105 |
$parser->parse($html); |
|
| 106 |
|
|
| 107 |
#print Dumper(\@lstEquipes); |
|
| 108 |
#print Dumper(\@lstJournees); |
|
| 109 |
#print Dumper(\%matchs); |
|
| 110 |
|
|
| 111 |
my $fh; |
|
| 112 |
my $i; |
|
| 113 |
open($fh, '>', 'tmp/equipes') or die $!; |
|
| 114 |
foreach (@lstEquipes) {
|
|
| 115 |
print $fh $_."\n"; |
|
| 116 |
} |
|
| 117 |
close($fh); |
|
| 118 |
|
|
| 119 |
open($fh, '>', 'tmp/journees') or die $!; |
|
| 120 |
$i = 0; |
|
| 121 |
foreach (@lstJournees) {
|
|
| 122 |
$i++; |
|
| 123 |
print $fh "tour n° $i du $_\n"; |
|
| 124 |
} |
|
| 125 |
close($fh); |
|
| 126 |
|
|
| 127 |
foreach my $journee (keys %matchs) {
|
|
| 128 |
foreach my $match (keys %{$matchs{$journee}}) {
|
|
| 129 |
open($fh, '>', "tmp/match-$journee-$match") or die $!; |
|
| 130 |
print $fh $matchs{$journee}{$match};
|
|
| 131 |
close($fh); |
|
| 132 |
} |
|
| 133 |
} |
|
| 134 |
|
|
Formats disponibles : Unified diff