[Thread Prev][Thread Next][Thread Index]

Re: here it is, Sun namelist download?



See attached, written by Dave Brillhart  (c) 1997


> Date: Fri, 12 Mar 1999 16:03:04 -0500 (EST)
> From: "Richard.Stone" <Richard.Stone@East>
> Subject: Sun namelist download?
> To: pilotmgr@xxxxxxxxxxxxxxxxxxxxxxx
> MIME-Version: 1.0
> 
> Hopefully this is the appropriate alias to ask this question.......
> 
> Is there a facility to download a specific subset of the Sun employee phone
> list to a Palm III?
> 
> Regards,
> Dick
> 
> ------------------------------------------------------------------------
> ***********************************************************
> *             This is a public mailing list!              *
> * Please do not publish Sun proprietary information here! *
> *        -  -  -  -  -  -  -  -  -  -  -  -  -  -         *
> *             http://www.moshpit.org/pilotmgr             *
> ***********************************************************

---------------------------------------------------------------
Neal S. Pollack   310-348-6129  Extension  46129
Solaris Engineering Mgr, Sun Microsystems Inc.
Los Angeles, Ca. 90045     EMAIL: Neal.Pollack@xxxxxxx
#!/usr/local/bin/perl5.002 -w
#############################################################################
# Script name:   pilot_names
# Author:        Dave Brillhart  (c) 1997
# Last Modified: 4 Dec 1997
#
# Note: works for US listings... but easily modified for international use
#
# DESCRIPTION
#   Grabs and parses contact info from Sun's "names" database and
#   prepares a sorted file in any of three formats as follows.
#   The first two are appropriate for importing into PDAs, such as
#   the PalmPilot. By default it grabs all of Southern Area, but
#   it accepts optional MAILSTOPS in the format: UXXXNN.
#
#     pilot_names -t           (tab seperated)
#     pilot_names -c           (comma seperated)
#     pilot_names -p           (nicer format for printer or screen)
#     pilot_names -h           (help on importing to pilot)
#
#     Ex:  pilot_names -c uorl02 uatl04
#     Ex:  pilot_names -t -f names.tab
#     Ex:  (pilot_names -t upal01 upal02) > /tmp/pal.txt
#
#   These examples produce a sorted:
#     - comma seperated listing of everyone in Atlanta and Orlando
#     - tab seperated listing of everyone in the Southern Area (close to 700)
#     - tab seperated listing of everyone in PaloAlto (over 800) to a file.
#
#  I loaded 680 records for the entire Southern Area and it took up
#  55KB on my PalmPilot. I will enhance this to include pager and cellphone
#  data someday. Send bug reports to: Dave.Brillhart@xxxxxxx
#
#  The code ain't pretty but it works. I run it using Perl 5.004_04
#############################################################################

$debug = $flg = $tab = $comma = $help = $pretty = 0;

#@florida = (uorl02,umlb01,utpa02,ufll02,ujax04,utal01);
#@georgia = (uatl04);
#@tennessee = (umem01,umem02,umem03,unsv01,uknv01);
#@northcarolina = (ucry03,uclt02);
#@alabama = (uhsv02,umob01,ubhm01);
#@virginia = (uhmp01,uric02,uvnn06,ursn01);
#@maryland = (ubwi03,ubwi04);
#@dc = (uwas02);

#@southernareaoffices = (@florida,@georgia,@tennessee,@maryland,@dc,
#                        @northcarolina,@alabama,@virginia);

@ssla = (ulax01);
@lax = (ueg002);
@encino = (uen001);

@westla = (@ssla,@lax,@encino);

#@mailstops = @southernareaoffices;
@mailstops = @westla;

# -- Parse command line args
while (($arg = shift(@ARGV))) {
  if    ($arg eq "-d") { $debug = 1; }
  elsif ($arg eq "-t") { $tab = 1; }
  elsif ($arg eq "-c") { $comma = 1; }
  elsif ($arg eq "-p") { $pretty = 1; }
  elsif ($arg eq "-h") { $help = 1; }
  elsif ($arg =~ m/U[A-Z]{3,3}[0-9][0-9]/i)
    { if (! $flg++) { @mailstops=() }; push(@mailstops, $arg); }
  else { printf("\nERROR: bad command line arg ($arg)\n");  exit(3); }
}

if ($help + $tab + $comma + $pretty > 1) {
  printf("\nERROR: only specify one of: -h, -t, -c, -p\n");  exit(3); }

if ($help + $tab + $comma + $pretty == 0) {
  printf("\nERROR: specify one of: -h (help) -t (tab), -c (comma), -p (pretty)\n");  exit(3); }

if ($help) { &pilotHelp; exit; }

#
# Populate an array with entries from namex for each mailstop
# Do not include entries that are missing E-mail or Phone
#
foreach $mailstop (@mailstops) {
  $syscmd = "namex $mailstop | grep '\@' | grep -v '#' |";

  # -- open a pipe from the command
  if (! open(CMD, $syscmd)) {
    printf("ERROR: open command ($syscmd)"); exit(3);
  }

  while ($line = <CMD>) {
    chop $line; $line = &squeezeSTR($line);
    if ($debug) { print "$line\n"; }
    push (@lines, $line);
    $rowcnt++;
  }
  close CMD;

  if ($debug) { print "ROWCOUNT: ($mailstop)  $rowcnt\n"; }
}

#
# Process lines into clean useful entries
# Search for valid 5 digit and 10/11 digit phone numbers
# Use Fname, Lname as found in E-mail addr (nicknames)
#
foreach $line (@lines) {
  &validateLines($line);
  ($ext, $full) = &getPhoneNumbers($line);
  if ($debug) { print "PHONE NUMBERS: $ext  $full\n"; }
  $email = &getEmail($line);
  $ms = &getMailStop($line);
  ($first, $last) = &getName($line);
  $fchar = substr($first,0,1); $fchar =~ tr/a-z/A-Z/; substr($first,0,1) = $fchar;
  $lchar = substr($last,0,1); $lchar =~ tr/a-z/A-Z/; substr($last,0,1) = $lchar;

  $record = join('^',$last,$first,$ext,$full,$ms,$email);
  push(@records,$record);
}

# SORT BY LAST NAME
local(@datakeys);
foreach (@records) {
  push(@datakeys, (split(/\^/))[0]);
}
sub bydatakeys { $datakeys[$a] cmp $datakeys[$b]; }
@sortdata = @records[sort bydatakeys $[..$#records];

foreach $record (@sortdata) {
  ($ln,$fn,$ex,$pn,$ms,$em) = split(/\^/,$record);
  if ($pn ne "---") { $pn = '(' . substr($pn,0,3) . ')' . 
                      substr($pn,3,3) . '-' . substr($pn,6); }
  $nm = "$ln, $fn";
  if ($pretty) { printf("%-30s  %5s    %13s    %s    %s\n",$nm,$ex,$pn,$ms,$em); }
  if ($tab)    { printf("%s\t%s\t%s\t%s\t%s\t%s\n",$ln,$fn,$ex,$pn,$ms,$em); }
  if ($comma)  { printf("%s,%s,%s,%s,%s,%s\n",$ln,$fn,$ex,$pn,$ms,$em); }
}


#
# Get Fname, Lname
#
sub getName {
  local($raw) = @_;
  local($fname) = ''; local($lname) = '';

  ($fname,$lname) = $raw =~ m/^[\*()A-Z\.\-'\s]+,\s+[,()\.A-Z\-'\s]+\s+([a-z\-]+)[\.a-z]*\.([a-z\-]+)\@[a-zA-Z]+\s+U[A-Z]{3,3}[0-9][0-9]\-*[A-Z0-9]*\s+.*$/;

  if ($debug && (!$fname || !$lname)) { print "INVALID NAME: $raw\n"; }

  if (!$fname)  { $fname = "---"; }
  if (!$lname)  { $lname = "---"; }

  return($fname,$lname);
}

#
# Get MailStop
#
sub getMailStop {
  local($raw) = @_;
  local($ms) = '';

  ($ms) = $raw =~ m/^[\*()A-Z\.\-'\s]+,\s+[,()\.A-Z\-'\s]+\s+[a-z\-]+[\.a-z]*\.[a-z\-]+\@[a-zA-Z]+\s+U([A-Z]{3,3})[0-9][0-9]\-*[A-Z0-9]*\s+.*$/;

  if ($debug && !$ms) { print "INVALID MAILSTOP: $raw\n"; }

  if (!$ms)  { $ms = "---"; }

  return($ms);
}

#
# Get Email
#
sub getEmail {
  local($raw) = @_;
  local($email) = '';

  ($email) = $raw =~ m/^[\*()A-Z\.\-'\s]+,\s+[,()\.A-Z\-'\s]+\s+([a-z\-]+[\.a-z]*\.[a-z\-]+\@[a-zA-Z]+)\s+U[A-Z]{3,3}[0-9][0-9]\-*[A-Z0-9]*\s+.*$/;

  if ($debug && !$email) { print "INVALID EMAIL: $raw\n"; }

  if (!$email)  { $email = "---"; }

  return($email);
}

#
# Get phone numbers
#
sub getPhoneNumbers {
  local($raw) = @_;
  local($ext) = ''; local($full) = '';

  # grab data following valid mailstop - so mailstop won't
  # run into phone number and corrupt matching process
  ($semiraw) = $raw =~ m/^.*u[a-z]{3,3}[0-9][0-9]\-*[A-Z0-9]*\s+(.*)$/i;

  # remove spaces, dashes, parens to looks for valid numbers
  $semiraw =~ tr/ \-()//d; $semiraw = ' ' . $semiraw . ' ';

  ($ext) = $semiraw =~ m/\D([0-9]{5,5})\D/;
  ($full) = $semiraw =~ m/\D1*([0-9]{10,10})\D/;
  ($fulla,$fullb) = $semiraw =~ m/\D1*([0-9]{10,10})\D+1*([0-9]{10,10})\D/;

  if ($debug && $fulla && $fullb && $fulla != $fullb) { 
    print "INCONSISTANT FULL TELE: $raw\n"; }
  if ($debug && !$full) { print "MISSING FULL TELE: $raw\n"; }

  if (!$ext)  { $ext = "---"; }
  if (!$full) { $full = "---"; }

  return($ext,$full);
}


#
# Validate Lines
#
sub validateLines {
  local($raw) = @_;

  if (!($raw =~ m/^[\*()A-Z\.\-'\s]+,\s+[,()\.A-Z\-'\s]+\s+[a-z\-]+[\.a-z]*\.[a-z\-]+\@[a-zA-Z]+\s+U[A-Z]{3,3}[0-9][0-9]\-*[A-Z0-9]*\s+.*$/)) { print "INVALID LINE: $raw\n"; }
}

#
# Help file for importing to the Pilot
#
sub pilotHelp {

  print "======================================================================\n";
  print "Help File - Importing Data to PalmPilot\n";
  print "======================================================================\n";
  print "(bug reports: dave.brillhart\@sun.com)\n";
  print "----------------------------------------------------------------------\n";
  print " 1.) \$ (pilot_names -c [list of mailstops]) > /tmp/names.txt\n";
  print " 2.) \$ unix2dos /tmp/names.txt > /tmp/names.csv\n";
  print " 3.) <copy file to PC that is running PilotDesktop 2.0 S/W>\n";
  print " 4.) <fire up PilotDesktop and click on Address>\n";
  print " 5.) <create a new category called AutoSun and switch to it>\n";
  print " 6.) <hit File->Import, FileType=Comma Seperated>\n";
  print " 7.) <open the data file called: names.csv>\n";
  print " 8.) <sort field order: last, first, other, work, city, e-mail\n";
  print " 9.) <make sure only those six fields are checked>\n";
  print "10.) <hit ok to read in all records>\n";
  print "11.) <hit File->SaveAll>\n";
  print "12.) <place PalmPilot in HotSync Cradle and Sync it!!>\n";
  print "======================================================================\n";
  print "Note: use a seperate category called AutoSun so you can kill them\n";
  print "all and reload with new auto-generated data... this preserves all\n";
  print "your other address entries\n";
  print "----------------------------------------------------------------------\n";
  print "DESCRIPTION\n";
  print "  Grabs and parses contact info from Sun's \"names\" database and\n";
  print "  prepares a sorted file in any of three formats as follows.\n";
  print "  The first two are appropriate for importing into PDAs, such as\n";
  print "  the PalmPilot. By default it grabs all of Southern Area, but\n";
  print "  it accepts optional MAILSTOPS in the format: UXXXNN.\n";
  print "\n";
  print "     pilot_names -t           (tab seperated)\n";
  print "     pilot_names -c           (comma seperated)\n";
  print "     pilot_names -p           (nicer format for printer or screen)\n";
  print "     pilot_names -h           (help on importing to pilot)\n";
  print "\n";
  print "     Ex:  pilot_names -c uorl02 uatl04\n";
  print "     Ex:  pilot_names -t -f names.tab\n";
  print "     Ex:  (pilot_names -t upal01 upal02) > /tmp/pal.txt\n";
  print "\n";
  print "  These examples produce a sorted:\n";
  print "    - comma seperated listing of everyone in Atlanta and Orlando\n";
  print "    - tab seperated listing of everyone in the Southern Area (close to 700)\n";
  print "    - tab seperated listing of everyone in PaloAlto (over 800) to a file.\n";
  print "\n";
  print "  I loaded 680 records for the entire Southern Area and it took up\n";
  print "  55KB on my PalmPilot. I will enhance this to include pager and cellphone\n";
  print "  data someday. Send bug reports to: Dave.Brillhart\@sun.com\n";
  print "\n";
  print "  The code ain't pretty but it works. I run it using Perl 5.004_04\n";
  print "========================================================================\n";
}  


#
# convert all whitespace to spaces and squeeze.
# remove leading and trailing whitespace.
#
sub squeezeSTR {
  local($str) = @_;
  local($1);

  if (! defined($str) || length($str) == 0) { return $str; }
  $str = ' ' . $str . ' '; #required to make trim easier
  $str =~ tr/ 	/ /s; # a space and a tab
  $1 = ''; $str =~ m/^\s+(.*)\s+$/; $str = $1;

  return $str;
}

SourceForge.net Logo