-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmtg2.pl
executable file
·65 lines (55 loc) · 1.29 KB
/
mtg2.pl
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
#!/usr/bin/env perl
use Getopt::Std;
use mtg;
getopt('naN', \%opts);
if (!$opts{'n'} && !$opts{'a'} && !$opts{'N'}) { die "-n - search by name, -N - search by multiverseid, -a - search by artist.\n";}
if ($opts{'N'}) {
if ($opts{'N'} =~ /\d+/ ) {
print mtg::header;
$entry = mtg::get_entry $opts{'N'};
print mtg::print_entry ($entry, 0);
print '<images>';
print mtg::image $entry->{image1};
if ($entry->{image2}) {
print mtg::image $entry->{image2};
}
print '</images></collection></tellico>';
}
else {
die "-N value is not a number.\n";
}
}
elsif ($opts{'n'} || $opts{'a'} ) {
if ($opts{'n'}) {
$sstr = $opts{'n'};
$sstr =~ s/\s+/]+[/g;
$sstr = "name=+[".$sstr."]";
}
else {
$sstr = $opts{'a'};
$sstr =~ s/\s+/]+[/g;
$sstr = "artist=+[".$sstr."]";
}
%wyniki = mtg::search($sstr);
@lista = keys %wyniki;
$i=0;
my @images;
print mtg::header;
while (($n = shift @lista) && ($i < 10)) {
$entry = mtg::get_entry $n;
print mtg::print_entry ($entry, $i);
push @images, $entry->{image1};
if ($entry->{image2}) {
push @images, $entry->{image2};
}
$i++;
}
print '<images>';
#pozbycie sie duplikatow
%hash = map { $_, 1 } @images;
@images = keys %hash;
while ($n = shift @images) {
print mtg::image $n;
}
print '</images></collection></tellico>';
}