add CTY-3304
[spider.git] / cmd / dxqsl_import.pl
1 #
2 # Import QSL information to the local database
3 #
4 # Copyright (c) 2010 Dirk Koopman G1TLH
5 #
6
7 my ($self, $line) = @_;
8 my ($fn) = $line;
9 return (1, $self->msg('e5')) if $self->priv < 9;
10 return (1, "import_dxqsl: <pathname to import from>") unless $fn;
11
12 #$DB::single=1;
13
14 return (1, $self->msg('db3', 'QSL')) unless $QSL::dbm;
15
16 my $if = IO::File->new("$fn") or return(1, $self->msg('e30', $fn));
17 my $count;
18 while (<$if>) {
19         next if /^\s+"/;
20         chomp;
21         my ($call, $manager, $c, $t, $by) = split /\s*,\s*/;
22         if ($call && $by) {
23                 my $q = QSL::get($call) || QSL->new($call);
24                 my ($r) = grep {$_->[0] eq $manager} @{$q->[1]};
25                 if ($r) {
26                         $r->[1] += $c;
27                         if ($t > $r->[2]) {
28                                 $r->[2] = $t;
29                                 $r->[3] = $by;
30                         }
31                 } else {
32                         $r = [$manager, $by, $t, $by];
33                         unshift @{$q->[1]}, $r;
34                 }
35                 $q->put;
36                 ++$count;
37         }
38 }
39
40 $if->close;
41
42 return(0, $self->msg("db10", $count, $fn, 'dxqsl'));