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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
| #!/usr/local/bin/perl
use strict;
use WWW::Mechanize;
use HTTP::Cookies;
use XML::Twig;
use agence;
use monstre;
my $mon_agence;
my $api_login = 'monloginapi';
my $api_pass = 'monmotdepasseapi';
my @Liste_monstre;
my @Liste_contrat;
my @Liste_equipement;
my @Liste_ressource;
my @Liste_ampe;
my $link_xml_agence = 'http://www.croquemonster.com/api/agency.xml?name='.$api_login.';pass='.$api_pass;
my $link_xml_monstre = 'http://www.croquemonster.com/api/monsters.xml?name='.$api_login.';pass='.$api_pass;
my $link_xml_contrat = 'http://www.croquemonster.com/api/contracts.xml?name='.$api_login.';pass='.$api_pass;
my $link_xml_inventaire = 'http://www.croquemonster.com/api/inventory.xml?name='.$api_login.';pass='.$api_pass;
my $bot = WWW::Mechanize->new(
agent => 'Mozilla/4.73 [en] (X11; I; Linux 2.2.16 i686; Nav)',
cookie_jar => HTTP::Cookies->new(
file => "croquecookies.txt",
autosave => 1,
)
);
&main();
sub main{
&load_xml($link_xml_agence,'agence');
&load_xml($link_xml_monstre,'monstre');
&load_xml($link_xml_contrat,'contrat');
&load_xml($link_xml_inventaire,'inventaire');
&parse_agence();
&parse_monstre();
&parse_contrat();
}
sub load_xml{
my $var = $_[0];
my $temp = $_[1];
print "Chargement $temp \n";
$bot->get($var);
die $bot->res->status_line if not $bot->success;
my $string = $bot->content;
if (index($string, '<err error="Unknown user"/>') > 0 ) { print "Utilisateur inconnue \n"; exit; }
if (index($string, '<err error="Unknown syndicate"/>') > 0 ) { print "Syndicat inconnue \n"; exit; }
if (index($string, '<err error="API access disabled"/>') > 0 ) { print "API non active \n"; exit; }
if (index($string, '<err error="Bad password"/>') > 0 ) { print "Mot de passe eronne \n";exit; }
while (index($string, '<locked/>') > 0 )
{
$bot->get($var);
die $bot->res->status_line if not $bot->success;
my $string = $bot->content;
sleep(10);
}
$string =~ s/<description>(.+)<\/description>//gs;
open(ECRIRE,">".$temp.".xml");
print ECRIRE '<?xml version="1.0" encoding="UTF-8"?>';
print ECRIRE "\n";
print ECRIRE $string;
close ECRIRE;
}
sub parse_agence{
my $twig= XML::Twig->parse("agence.xml");
my $root = $twig->root;
my $syndicat;
my $syndicatid;
foreach my $TwigPersonne ( $root )
{
if (defined($TwigPersonne->att('syndicate'))) { $syndicat = $TwigPersonne->att('syndicate');}else{$syndicat ='';}
if (defined($TwigPersonne->att('syndicateId'))) { $syndicatid = $TwigPersonne->att('syndicateId');}else{$syndicatid = 0;}
$mon_agence = agence->new($TwigPersonne->att('id'),$TwigPersonne->att('name'),$TwigPersonne->att('days'),$TwigPersonne->att('level'),$TwigPersonne->att('score'),$TwigPersonne->att('reputation'),$TwigPersonne->att('portails'),$TwigPersonne->att('cities'),$TwigPersonne->att('monsters'),$TwigPersonne->att('maxMonsters'),$TwigPersonne->att('scared'),$TwigPersonne->att('devoured'),$TwigPersonne->att('contractsA'),$TwigPersonne->att('failedA'),$TwigPersonne->att('contractsB'),$TwigPersonne->att('failedB'),$TwigPersonne->att('contractsC'),$TwigPersonne->att('failedC'),$TwigPersonne->att('contractsD'),$TwigPersonne->att('failedD'),$syndicat,$syndicatid,$TwigPersonne->att('gold'),$TwigPersonne->att('mails'));
}
}
sub parse_monstre{
my $twig= XML::Twig->parse("monstre.xml");
my $root = $twig->root;
my $contract;
my $attack;
my $racket;
foreach my $TwigMonstre ( $root->children )
{
if (defined($TwigMonstre->att('contract'))) { $contract = $TwigMonstre->att('contract');}else{$contract =0;}
if (defined($TwigMonstre->att('attack'))) { $attack = $TwigMonstre->att('attack');}else{$attack =0;}
if (defined($TwigMonstre->att('racket'))) { $racket = $TwigMonstre->att('racket');}else{$racket =0;}
my $monstre = monstre->new($TwigMonstre->att('id'),$TwigMonstre->att('name'),$TwigMonstre->att('sadism'),$TwigMonstre->att('ugliness'),$TwigMonstre->att('power'),$TwigMonstre->att('greediness'),$TwigMonstre->att('control'),$TwigMonstre->att('fight'),$TwigMonstre->att('endurance'),$TwigMonstre->att('bounty'),$TwigMonstre->att('successes'),$TwigMonstre->att('failures'),$TwigMonstre->att('devoured'),$TwigMonstre->att('firePrize'),$TwigMonstre->att('fatigue'),$contract,$attack,$racket,$TwigMonstre->att('permanentItems'),$TwigMonstre->att('contractItems'));
push(@Liste_monstre,$monstre);
}
}
sub parse_contrat{
my $twig= XML::Twig->parse("contrat.xml");
my $root = $twig->root;
} |
Partager