download gen_usdb_data.pl
Language: Perl
Copyright: (c) 2002 Dirk Koopman G1TLH
LOC: 77
Project Info
DXSpider DX Cluster System(dxspider)
Server: SourceForge
Type: cvs
...pider\dxspider\spider\perl\
   AGWConnect.pm
   AGWMsg.pm
   AnnTalk.pm
   BadWords.pm
   Bands.pm
   BBS.pm
   Buck.pm
   call.pl
   callbot.pl
   Chain.pm
   cluster.pl
   CmdAlias.pm
   connect.pl
   console.pl
   Console.pm
   convert_users.pl
   convkeps.pl
   create_prefix.pl
   create_qsl.pl
   create_sysop.pl
   create_usdb.pl
   DB0SDX.pm
   DXBearing.pm
   dxcc.pl
   DXChannel.pm
   DXCommandmode.pm
   DXConnect.pm
   DXCron.pm
   DXDb.pm
   DXDebug.pm
   DXDupe.pm
   DXHash.pm
   DXLog.pm
   DXLogPrint.pm
   DXM.pm
   DXMsg.pm
   dxoldtonew.pl
   DXProt.pm
   DXProtout.pm
   DXProtVars.pm
   DXSql.pm
   DXUser.pm
   DXUtil.pm
   DXVars.pm.issue
   DXXml.pm
   Editable.pm
   export_opernam.pl
   ExtMsg.pm
   Filter.pm
   ForkingServer.pm
   gen_usdb_data.pl
   Geomag.pm
   hlptohtml.pl
   importkeps.pl
   importwwv.pl
   Internet.pm
   IntMsg.pm
   Investigate.pm
   IsoTime.pm
   Julian.pm
   K4UTE.pm
   Keps.pm
   Listeners.pm
   Local.pm
   lock_nodes.pl
   log2csv.pl
   LRU.pm
   Minimuf.pm
   MiscLog.pm
   Mrtg.pm
   Msg.pm
   PC.pm
   Prefix.pm
   process_ursa.pl
   Prot.pm
   proto.html
   QRZ.pm
   QSL.pm
   RingBuf.pm
   Route.pm
   RouteDB.pm
   Script.pm
   Spot.pm
   spot2csv.pl
   Sun.pm
   talias.pl
   Thingy.pm
   Timer.pm
   UDPMsg.pm
   update_sysop.pl
   USDB.pm
   VE7CC.pm
   Verify.pm
   WCY.pm
   winclient.pl
   y2k.sh

#!/usr/bin/perl
#
# Something to create my subset of the US call book data,
# in my flat file form, either from the main data base or
# else the daily updates. 
#
# You can get the main database from: 
#
#   http://wireless.fcc.gov/uls/data/complete/l_amat.zip
#
# The daily data bases are available as a set of seven from here:-
#
#   http://wireless.fcc.gov/uls/data/daily/l_am_sat.zip 
#   http://wireless.fcc.gov/uls/data/daily/l_am_sun.zip 
#   http://wireless.fcc.gov/uls/data/daily/l_am_mon.zip 
#   http://wireless.fcc.gov/uls/data/daily/l_am_tue.zip 
#   http://wireless.fcc.gov/uls/data/daily/l_am_wed.zip 
#   http://wireless.fcc.gov/uls/data/daily/l_am_thu.zip 
#   http://wireless.fcc.gov/uls/data/daily/l_am_fri.zip
# 
# this program expects one or more zip files containing the call book
# data as arguments.
#
# Copyright (c) 2002 Dirk Koopman G1TLH
#
# $Id: gen_usdb_data.pl,v 1.5 2002/10/15 13:04:48 minima Exp $
#

use strict;

# make sure that modules are searched in the order local then perl
BEGIN {
	# root of directory tree for this system
	use vars qw($root);
	
	$root = "/spider"; 
	$root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'};

	unshift @INC, "$root/perl";	# this IS the right way round!
	unshift @INC, "$root/local";
}

use vars qw($VERSION $BRANCH);
$VERSION = sprintf( "%d.%03d", q$Revision: 1.5 $ =~ /(\d+)\.(\d+)/ );
$BRANCH = sprintf( "%d.%03d", q$Revision: 1.5 $ =~ /\d+\.\d+\.(\d+)\.(\d+)/  || (0,0));
$main::build += $VERSION;
$main::branch += $BRANCH;

use DXVars;
use Archive::Zip qw(:ERROR_CODES);
use Archive::Zip::MemberRead;
use IO::File;
use Compress::Zlib;

my $blksize = 1024 * 1024;

STDOUT->autoflush(1);

my $dbrawfn = "$main::data/usdbraw.gz";

rename "$dbrawfn.oo", "$dbrawfn.ooo";
rename "$dbrawfn.o", "$dbrawfn.oo";
rename "$dbrawfn", "$dbrawfn.o";
my $gzfh = gzopen($dbrawfn, "wb") or die "Cannot open $dbrawfn $!";

my $ctycount;
  
foreach my $argv (@ARGV) {
	my $zip = new Archive::Zip($argv) or die "Cannot open $argv $!\n";
	print "Doing $argv\n";
	handleEN($zip, $argv);
	handleAM($zip, $argv);
	handleHS($zip, $argv);
}

$gzfh->gzclose;

exit(0);

sub handleEN
{
	my ($zip, $argv) = @_;
	my $mname = "EN.dat";
	my $ofn = "$main::data/$mname";
	print "  Handling EN records, unzipping";
	if ($zip->extractMember($mname, $ofn) == AZ_OK) {
		my $fh = new IO::File "$ofn" or die "Cannot open $ofn $!";
		if ($fh) {
			
			print ", storing";
			
			my $count;
			my $buf;
			
			while (my $l = $fh->getline) {
				$l =~ s/[\r\n]+$//;
				my ($rt,$usi,$ulsfn,$ebfno,$call,$type,$lid,$name,$first,$middle,$last,$suffix,
					$phone,$fax,$email,$street,$city,$state,$zip,$pobox,$attl,$sgin,$frn) = split /\|/, $l;

#				print "ERR: $l\n" unless $call && $city && $state;

				if ($call && $city && $state) {
					my $rec = uc join '|', $call,$city,$state if $city && $state;
					$buf .= "$rec\n";
					if (length $buf > $blksize) {
						$gzfh->gzwrite($buf);
						undef $buf;
					}
					$count++;
				}
			}
			$gzfh->gzwrite($buf) if length $buf;
			print ", $count records\n";
			$fh->close;
		}
		unlink $ofn;
	} else {
		print "EN missing in $argv\n";
		return;
	}
}

sub handleAM
{

}

sub handleHS
{

}

About Koders | Resources | Downloads | Support | Black Duck | Submit Project | Terms of Service | DMCA | Privacy Policy | Site Map| Contact Us