X-Git-Url: http://www.dxcluster.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2Fcreate_localqsl.pl;h=e3f447f0c64e1ce341ad0723aa305a3695e27f98;hb=defc60f3e7fab9bb99d1c9f7b8bccc4ec37628d5;hp=2d3fc57e6fa0c7772a78f4bd4019e36f26e3221c;hpb=8032b90ab5f686159bc725b43d28862c42ad55d5;p=spider.git diff --git a/perl/create_localqsl.pl b/perl/create_localqsl.pl index 2d3fc57e..e3f447f0 100755 --- a/perl/create_localqsl.pl +++ b/perl/create_localqsl.pl @@ -27,7 +27,14 @@ use DXUtil; use Spot; use DXDb; +use vars qw($end $lastyear $lastday); + +$end = 0; +$SIG{TERM} = $SIG{INT} = sub { $end++ }; + my $qslfn = "localqsl"; +$lastyear = 0; +$lastday = 0; $main::systime = time; @@ -38,20 +45,30 @@ unless ($db) { DXDb::load(); $db = DXDb::getdesc($qslfn); } - die "cannot load $qslfn $!" unless $db; +# find start point (if any) +my $statefn = "$root/data/$qslfn.state"; +my $s = readfilestr($statefn); +eval $s if $s; + my $base = "$root/data/spots"; opendir YEAR, $base or die "$base $!"; foreach my $year (sort readdir YEAR) { next if $year =~ /^\./; + next unless $year ge $lastyear; + my $baseyear = "$base/$year"; opendir DAY, $baseyear or die "$baseyear $!"; foreach my $day (sort readdir DAY) { - next if $day =~ /^\./; + next unless $day =~ /(\d+)\.dat$/; + my $dayno = $1 + 0; + next unless $dayno >= $lastday; + my $fn = "$baseyear/$day"; my $f = new IO::File $fn or die "$fn ($!)"; + print "doing: $fn\n"; while (<$f>) { if (/(QSL|VIA)/i) { my ($freq, $call, $t, $comment, $by, @rest) = split /\^/; @@ -62,6 +79,10 @@ foreach my $year (sort readdir YEAR) { } } } + $f->close; + $f = new IO::File ">$statefn" or die "cannot open $statefn $!"; + print $f "\$lastyear = $year; \$lastday = $dayno;\n"; + $f->close; } } @@ -76,23 +97,20 @@ sub update # decode the lines foreach my $l (@lines) { - my ($date, $time, $oby, $ocom) = $l =~ /^(\s?\S+)\s+(\s?\S+)\s+by\s+(\S+):\s+(.*)$/; + my ($date, $time, $oby, $ocom) = $l =~ /^(\s?\S+)\s+(\s?\S+)\s+de\s+(\S+):\s+(.*)$/; if ($date) { my $ot = cltounix($date, $time); push @in, [$ot, $oby, $ocom]; - } else { - print "Cannot decode $call: $l\n"; - $DB::single = 1; } - } # is this newer than the earliest one? if (@in && $in[0]->[0] < $t) { @in = grep {$_->[1] ne $by} @in; } - unshift @in, [$t, $by, $comment]; - pop @in, if @in > 5; - return join "\n", (map {(cldatetime($_->[0]) . " by $_->[1]: $_->[2]")} @in); + $comment =~ s/://g; + unshift @in, [$t, $by, $comment] if grep /^bur/i || is_callsign(uc $_), split(/\b/, $comment); + pop @in, if @in > 10; + return join "\n", (map {(cldatetime($_->[0]) . " de $_->[1]: $_->[2]")} @in); }