File: get-fcc-rac.pl

package info (click to toggle)
xastir 2.1.0-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 15,204 kB
  • sloc: ansic: 113,888; perl: 7,503; sh: 5,711; cpp: 2,651; makefile: 604; python: 312; pascal: 159; sql: 102; sed: 93
file content (140 lines) | stat: -rwxr-xr-x 4,047 bytes parent folder | download
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/perl
#
#
# Copyright (C) 2000-2018 The Xastir Group
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#
# Updated on 7/5/03 to reflect the new directory structure
# N0VH
#
# Note: Run this script as root in order to write the files into the
# destination directory listed below, or change directory write access.
use File::Basename;
$dirname=dirname($0);
require ($dirname."/values.pl");

my $XASTIR_BASE="${prefix}/share/xastir";


# This script uses temporary storage space in /var/tmp to do its work.
chdir "/var/tmp";


#####################################################################
# Get the RAC database, process it.
#   Download size:  ~2MB
# Final file size: ~13MB
#####################################################################
#

$file  = "amateur.zip";
#$file2 = "amateur.rpt";
$file2 = "amateur.txt";


print STDERR "*********************************\n";
print STDERR "*** Fetching the RAC database ***\n";
print STDERR "*********************************\n";
#`wget -c http://205.236.99.41/%7Eindicatif/download/$file`;
`wget -c http://apc-cap.ic.gc.ca/datafiles/$file`;


if (-e $file && -r $file && -f $file) {

  print STDERR "***********************************\n";
  print STDERR "*** Installing the RAC database ***\n";
  print STDERR "***********************************\n";
  `unzip $file $file2`;
  `mv $file2 $XASTIR_BASE/fcc/AMACALL.LST`;
}

# Remove the RAC download files
unlink $file, $file2;


#####################################################################
# Get the FCC database, process it.
#   Download size:  ~84MB
# Final file size: ~101MB
#####################################################################
#
my $file  = "l_amat.zip";
my $file2 = "EN.dat";

 
print STDERR "*********************************\n";
print STDERR "*** Fetching the FCC database ***\n";
print STDERR "*********************************\n";
`wget -c http://wireless.fcc.gov/uls/data/complete/$file`;

if (-e $file && -r $file && -f $file) {

  my $file_out = "$XASTIR_BASE/fcc/$file2";

  # Get rid of characters "^M^M^J" which are sometimes present, sort
  # the file by callsign & remove old entries for vanity call access.
  print STDERR "*****************************************************\n";
  print STDERR "*** Filtering/sorting/installing the FCC database ***\n";
  print STDERR "*****************************************************\n";

  my %from = ();
 
  open FILE, "unzip -p $file $file2|" or die "Can't open $file2 in $file : $!";
  open FILE_OUT, '|-', "sort -k 5,5 -t \\| -o $file_out" or die "Can't sort $file_out : $!";
  while( <FILE> ) {
    if (/^EN\|(\d+)\|\|\|(\w+)\|.*/) {
      $x = $1;
      $z = $2;
      chop;
      chop;
      $y = $_;
      if (defined $from{$2}) { # check for vanity reassignment
        if ($from{$z} =~ /^EN\|(\d+)\|\|\|(\w+)\|.*/) {
          if ($1 < $x) {
            $replaced++;
            $from{$2} = $y;
          }
        }
      }
      else {
        $from{$2} = $_;
      }
    }
  }
  close FILE;
 
  for my $callsign ( keys %from ) {
    $total++;
    print FILE_OUT "$from{$callsign}\n";
  }
  close FILE_OUT;

  print STDERR "Total callsigns:  " . $total . ".\n";
  print STDERR " Replaced callsigns:  " . $replaced . ".\n";
}

# Remove the FCC download files
unlink $file;




print STDERR "*************\n";
print STDERR "*** Done! ***\n";
print STDERR "*************\n";