add an RBN line to progress
[spider.git] / perl / create_dxqsl.pl
1 #!/usr/bin/env perl
2 #
3 # Implement a 'GO' database list
4 #
5 # Copyright (c) 2003 Dirk Koopman G1TLH
6 #
7 #
8 #
9
10 # search local then perl directories
11 BEGIN {
12         use vars qw($root);
13         
14         # root of directory tree for this system
15         $root = "/spider"; 
16         $root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'};
17         
18         unshift @INC, "$root/perl";     # this IS the right way round!
19         unshift @INC, "$root/local";
20 }
21
22 use strict;
23
24 use IO::File;
25 use SysVar;
26 use DXUtil;
27 use Spot;
28 use QSL;
29
30 use vars qw($end $lastyear $lastday $lasttime);
31
32 $end = 0;
33 $SIG{TERM} = $SIG{INT} = sub { $end++ };
34
35 my $qslfn = "qsl";
36
37 $main::systime = time;
38
39 unlink "$data/qsl.v2";
40 unlink "$local_data/qsl.v2";
41
42 QSL::init(1) or die "cannot open QSL file";
43
44 my $base = localdata("spots");
45
46 my $tu = 0;
47 my $tr = 0;
48
49 opendir YEAR, $base or die "$base $!";
50 foreach my $year (sort readdir YEAR) {
51         next if $year =~ /^\./;
52         
53         my $baseyear = "$base/$year";
54         opendir DAY,  $baseyear or die "$baseyear $!";
55         foreach my $day (sort readdir DAY) {
56                 next unless $day =~ /(\d+)\.dat$/;
57                 my $dayno = $1 + 0;
58                 
59                 my $fn = "$baseyear/$day";
60                 my $f = new IO::File $fn  or die "$fn ($!)"; 
61                 print "doing: $fn";
62                 my $u = 0;
63                 my $r = 0;
64                 while (<$f>) {
65                         last if $end;
66                         if (/(QSL|VIA)/i) {
67                                 my ($freq, $call, $t, $comment, $by, @rest) = split /\^/;
68                                 my $q = QSL::get($call) || new QSL $call;
69                                 if ($q) {
70                                         $q->update($comment, $t, $by);
71                                         $lasttime = $t;
72                                         ++$u;
73                                         ++$tu;
74                                 }
75                         }
76                         ++$r;
77                         ++$tr;
78                 }
79                 printf " - Spots read %8d QSLs %6d\n", $r, $u;
80                 $f->close;
81                 last if $end;
82         }
83         last if $end;
84 }
85
86 print "Total Spots read: $tr - QSLs found: $tu\n";
87
88 QSL::finish();
89
90 exit(0);
91
92