2011-08-30 09:56:23 +00:00
|
|
|
#!/usr/bin/perl -w
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
2011-08-30 15:10:44 +00:00
|
|
|
my $dataFile = 'mtg-cards-data.txt';
|
|
|
|
my $setsFile = 'mtg-sets-data.txt';
|
2011-08-30 13:21:08 +00:00
|
|
|
my $knownSetsFile = 'known-sets.txt';
|
2011-08-30 09:56:23 +00:00
|
|
|
|
|
|
|
my $cards_count = 0;
|
|
|
|
|
2011-08-30 13:21:08 +00:00
|
|
|
my %knownSets;
|
2011-08-30 15:10:44 +00:00
|
|
|
my %sets;
|
|
|
|
my %cardsBySet;
|
2011-08-30 09:56:23 +00:00
|
|
|
my %cards;
|
|
|
|
|
2011-08-30 15:10:44 +00:00
|
|
|
sub toCamelCase {
|
|
|
|
my $string = $_[0];
|
|
|
|
$string =~ s/\b([\w']+)\b/ucfirst($1)/ge;
|
|
|
|
$string =~ s/[-,\s\']//g;
|
|
|
|
$string;
|
|
|
|
}
|
|
|
|
|
|
|
|
open (DATA, $dataFile) || die "can't open $dataFile";
|
|
|
|
while(my $line = <DATA>) {
|
|
|
|
my @data = split('\\|', $line);
|
|
|
|
$cardsBySet{$data[1]}{toCamelCase($data[0])} = \@data;
|
|
|
|
}
|
|
|
|
close(DATA);
|
|
|
|
|
|
|
|
open (DATA, $setsFile) || die "can't open $setsFile";
|
|
|
|
while(my $line = <DATA>) {
|
|
|
|
my @data = split('\\|', $line);
|
|
|
|
$sets{$data[0]}= $data[1];
|
|
|
|
}
|
|
|
|
close(DATA);
|
|
|
|
|
2011-08-30 13:21:08 +00:00
|
|
|
open (DATA, $knownSetsFile) || die "can't open $knownSetsFile";
|
|
|
|
while(my $line = <DATA>) {
|
|
|
|
my @data = split('\\|', $line);
|
2011-08-30 15:10:44 +00:00
|
|
|
$knownSets{$data[1]}= $data[0];
|
2011-08-30 13:21:08 +00:00
|
|
|
}
|
|
|
|
close(DATA);
|
|
|
|
|
|
|
|
|
2011-08-30 15:10:44 +00:00
|
|
|
open CARDS, "< added_cards.txt" or die;
|
2011-08-30 09:56:23 +00:00
|
|
|
while (<CARDS>) {
|
2012-06-19 20:50:20 +00:00
|
|
|
my $line = $_;
|
2012-06-30 16:25:41 +00:00
|
|
|
if ( $line =~/(\w.*)\/(\w.*)\.java/ ) {
|
2012-06-19 20:50:20 +00:00
|
|
|
my $set = $1;
|
|
|
|
my $card = $2;
|
2012-06-30 16:25:41 +00:00
|
|
|
if ($2 ne "Swamp" and $2 ne "Mountain" and $2 ne "Island" and $2 ne "Plains" and $2 ne "Forest") {
|
|
|
|
$cards_count++;
|
|
|
|
if (!exists($cards{$set})) {
|
|
|
|
$cards{$set} = [];
|
|
|
|
}
|
2012-06-19 20:50:20 +00:00
|
|
|
|
2012-06-30 16:25:41 +00:00
|
|
|
push @{$cards{$set}}, $card;
|
|
|
|
}
|
2012-06-19 20:50:20 +00:00
|
|
|
}
|
2011-08-30 09:56:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
open REPORT, "> added_cards_in_wiki_format.txt";
|
2012-06-30 16:25:41 +00:00
|
|
|
print REPORT "* Added cards ($cards_count):\n";
|
2011-08-30 09:56:23 +00:00
|
|
|
foreach my $set (keys(%cards)) {
|
2011-08-30 14:04:36 +00:00
|
|
|
if ($set ne "tokens") {
|
2012-06-19 20:50:20 +00:00
|
|
|
if (exists $knownSets{$set}) {
|
2012-06-30 16:25:41 +00:00
|
|
|
print REPORT " * $sets{$knownSets{$set}}: ";
|
2012-06-19 20:50:20 +00:00
|
|
|
} else {
|
|
|
|
print REPORT " $set: ";
|
|
|
|
}
|
|
|
|
my $first = 1;
|
|
|
|
foreach my $card (@{$cards{$set}}) {
|
|
|
|
if ($cardsBySet{$knownSets{$set}}{$card}) {
|
2012-08-14 11:34:35 +00:00
|
|
|
if ($first == 0) {
|
|
|
|
print REPORT "; ";
|
|
|
|
} else {
|
|
|
|
$first = 0;
|
|
|
|
}
|
2012-06-19 20:50:20 +00:00
|
|
|
print REPORT $cardsBySet{$knownSets{$set}}{$card}[0];
|
|
|
|
} else {
|
|
|
|
#$card =~ s/([A-Z]{1}[a-z]+)/ $1/g;
|
|
|
|
#$card =~ s/A Ether/ AEther/g;
|
|
|
|
print "not processed: $sets{$knownSets{$set}} $card\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
print REPORT "\n";
|
|
|
|
}
|
2011-08-30 14:04:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
close REPORT;
|