[JA] Re: Making a .csv file out of address list

  • From: Larry Cook <lcook@xxxxxxxxxx>
  • To: juno_accmail@xxxxxxxxxxxxx
  • Date: Sun, 20 Feb 2005 16:06:14 -0500

Hi Babette,
George Lunt wrote:
> The Dawn address book conversion program reads like it can do it.  Probably 
> be worth a try.  Just give it a Google to locate it...  <g>

I agree with George.  Dawn is probably the best choice.

If that doesn't work, attached is a Perl script I wrote, although you would 
need to install Perl in order to run the script.  I wrote it when I moved to 
Mozilla and wanted to import my address book from Juno.

NOTE: I wrote and ran this script on Linux.  It should work on Windows, but no 
guarantees.

Larry


-- Attached file included as plaintext by Ecartis --
-- File: juno2csv.pl

#!/usr/bin/perl

# The following is the format of an entry
# in the Juno addrbook.nv address book file:
#
# Type:Entry
# Email:polei3@xxxxxxxxx
# Alias:
# Name:
# Primary Phone:
# Birth:
# Address:
# Deleted:1
# Time:972174302

$IN="addrbook.nv";
$OUT="abook_juno.csv";

open(IN, $IN) || die "Cannot open $IN for reading: $!\n";
open(OUT, ">$OUT") || die "Cannot open $OUT for writing: $!\n";

while ($line=<IN>) {
    $line =~ s/\n$//; $line =~ s/\r$//;
    if ($line =~ /Type:(.*)/) {
        $type = $1;
        if ($type =~ /^Entry/) {

            # Email:
            $line=<IN>; $line =~ s/\n$//; $line =~ s/\r$//;
            if ($line =~ /Email:(.*)/) {
                $email = $1;
            } else {
                die "Unexpected field: $line\n";
            }
            print "Email=$email\n";

            # Alias:
            $line=<IN>; $line =~ s/\n$//; $line =~ s/\r$//;
            if ($line =~ /Alias:(.*)/) {
                $alias = $1;
            } else {
                die "Unexpected field: $line\n";
            }
            print "Alias=$alias\n";

            # Name:
            $line=<IN>; $line =~ s/\n$//; $line =~ s/\r$//;
            if ($line =~ /Name:(.*)/) {
                $name = $1;
            } else {
                die "Unexpected field: $line\n";
            }
            $name =~ /([^,]*),\s*(.*)/;
            $first = $2;
            $last = $1;
            if (length($first)) {
                $name = $first;
                if (length($last)) {
                    $name .= " $last";
                }
            } elsif (length($last)) {
                $name = $last;
            } else {
                $name = "";
            }
            print "First=$first\n";
            print "Last=$last\n";
            print "Name=$name\n";

            # Primary Phone:
            $line=<IN>; $line =~ s/\n$//; $line =~ s/\r$//;
            if ($line =~ /Primary Phone:(.*)/) {
                $phone = $1;
            } else {
                die "Unexpected field: $line\n";
            }
            print "Phone=$phone\n";

            # Birth:
            $line=<IN>; $line =~ s/\n$//; $line =~ s/\r$//;
            if ($line =~ /Birth:(.*)/) {
                $birth = $1;
            } else {
                die "Unexpected field: $line\n";
            }
            print "Birth=$birth\n";

            # Address:
            $line=<IN>; $line =~ s/\n$//; $line =~ s/\r$//;
            if ($line =~ /Address:(.*)/) {
                $address = $1;
            } else {
                die "Unexpected field: $line\n";
            }
            print "Address=$address\n";

            # Deleted:
            $line=<IN>; $line =~ s/\n$//; $line =~ s/\r$//;
            if ($line =~ /Deleted:(.*)/) {
                $deleted = $1;
            } else {
                die "Unexpected field: $line\n";
            }
            print "Deleted=$deleted\n";

            # Time:
            $line=<IN>; $line =~ s/\n$//; $line =~ s/\r$//;
            if ($line =~ /Time:(.*)/) {
                $time = $1;
            } else {
                die "Unexpected field: $line\n";
            }
            print "Time=$time\n";

            # Process the entry
            if ($deleted == "0") {
                print OUT 
"$first,$last,$name,$alias,$email,,$phone,,,,,$address" . ","x32 . "\n";
            }
        } elsif ($type =~ /^MList/) {
            # Name:
            $line=<IN>; $line =~ s/\n$//; $line =~ s/\r$//;
            if ($line =~ /Name:(.*)/) {
                $name = $1;
            } else {
                die "Unexpected field: $line\n";
            }
            print "Name=$name\n";

            # Deleted:
            $line=<IN>; $line =~ s/\n$//; $line =~ s/\r$//;
            if ($line =~ /Deleted:(.*)/) {
                $deleted = $1;
            } else {
                die "Unexpected field: $line\n";
            }
            print "Deleted=$deleted\n";

            # Time:
            $line=<IN>; $line =~ s/\n$//; $line =~ s/\r$//;
            if ($line =~ /Time:(.*)/) {
                $time = $1;
            } else {
                die "Unexpected field: $line\n";
            }
            print "Time=$time\n";

            # Member*:
            $line=<IN>; $line =~ s/\n$//; $line =~ s/\r$//;
            undef $members;
            while ($line =~ /Member[0-9]*:(.*)/) {
                $members .= $1 . "\n";
                $line=<IN>; $line =~ s/\n$//; $line =~ s/\r$//;
            }
            print "Members=\n$members";

            # Process the entry
            if ($deleted == "0") {
                open(LIST, ">$name.lst") || die "Cannot open $name.list for 
writing: $!\n";
                print LIST $members;
                close(LIST);
            }
        } else {
            print "Skipping Type=$type...\n";
        }
    }
}

close(IN);
close(OUT);

exit 0;




To unsubscribe, send a message to ecartis@xxxxxxxxxxxxx with
"unsubscribe juno_accmail" in the body or subject.
OR visit //freelists.org
~*~



Other related posts: