1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| use strict;
use warnings;
use strict;
use XML::Twig;
use utf8;
use LWP::UserAgent;
use LWP::Simple;
use Data::Dumper;
my $urlbase="http://utmb.livetrail.net/coureur.php"; #choix de l'url de la course livetrail
my $dossardsuivi="8"; #numéro de dossard impératif
my $url=$urlbase."?rech=".$dossardsuivi; #création de l'adresse php complète d'accès au suivi
getstore($url, 'suivilive.xml') or die 'Unable to get page'; #récupération des données html et enregistrement
# Création du fichier résultat
my $FichierResulat = 'resultat.txt';
open( my $FhResultat, '>', $FichierResulat )
or die("Impossible d'ouvrir le fichier $FichierResulat\n$!");
#routine cmcmc
my ($filename) = 'suivilive.xml';
{
my $c;
XML::Twig->new(
twig_handlers => {
map { my ($name, $id, $wanted) = @$_;
my @wanted_atts = @$wanted;
$name => sub { my ($t, $e) = @_;
my %h = map { $_ => $e->att($_)} @wanted_atts;
if ($id) {
$c->{$name}{$h{$id}} = \%h;
} else {
push @{$c->{$name}}, \%h;
}
} }
['identite', undef, [qw(nom prenom sx)]],
['e', 'idpt', [qw(idpt clt tps hd jd hd)]],
['pt', 'idpt', [qw(idpt km n d)]]
}) ->parsefile($filename);
print {$FhResultat} "Bienvenu sur le suivi live de $c->{identite}[0]{prenom} $c->{identite}[0]{nom}\n" ;
print {$FhResultat} "Depart de $c->{pt}{0}{n} : $c->{e}{0}{hd}\n" ;
print {$FhResultat} ("======================================\n\n");
#routine cmcmc trop complexe pour moi
#for (sort { $a <=> $b } keys %{$c->{e}}) {
#next unless $_;
#my ($idpt, $clt, $ha) = @{$c->{e}{$_}}{qw(idpt clt ha)};
#print "$c->{identite}[0]{prenom} est arrivee a $c->{pt}{$idpt}{n} : $ha - Classement : $clt\n";
#}
#affiche des résultats à chaque point de passage
foreach my $keys (sort {$a <=> $b} keys %{$c->{e}}) {
if ($keys!=0){
print {$FhResultat} "\n $c->{identite}[0]{prenom} est arrivee a $c->{pt}{$keys}{n} en $c->{e}{$keys}{clt}e position\n";
print {$FhResultat} "Distance parcourue : $c->{pt}{$keys}{km} km\nAscension : $c->{pt}{$keys}{d} m+\nChrono : $c->{e}{$keys}{tps}\n";
print {$FhResultat} ("---------------------------------------------------------------------------");
}
}
print("Fichier resultat.txt ok");
} |
Partager