The new Raspberry Pi B Model B+ is here - Pick one up in the store and check our detailed guide!

Gmail contacts to AdaFruit SIM loader format

by rabbitnyc on Mon Sep 13, 2010 9:08 pm

Hope someone else will find this useful. Make sure to get and download the "Text::CSV_PP" CPAN libraries. To get your Google contacts log into your gmail account select contacts; More actions; export; google CSV format.

Gustav




Code: Select all | TOGGLE FULL SIZE
#!/opt/local/bin/perl

#Copyright 2010 by Gustav von Roth, Gmail2AdaSIM[at]vonroth.com
#
#This software is free software; you can redistribute it and/or modify
#it under the same terms as Perl itself.


 use strict;
 use warnings;
 
 use lib '.';
 use Text::CSV_PP;

if(($#ARGV+1) != 2)  {
   print "Gmail2AdaSIM.pl <infile.csv> <outfile.txt>\n\n";
   print
   "\n".
   "example usage:"."\n".
   "perl Gmail2AdaSIM.pl google.csv gmail2AdaSim.csv"."\n"
   ;
   exit;
}

my $inFile  = $ARGV[0];
my $outFile = $ARGV[1];

               
    #open input file            
    open my $gmail_csv_fh, "<:encoding(UTF-16)", $inFile or die "$inFile: $!";
    my $gmail_csv = Text::CSV_PP->new({ binary => 1});
    my $status = $gmail_csv->getline ($gmail_csv_fh);
    my @headerNames = $gmail_csv->fields();

    $gmail_csv->column_names (@headerNames);

    open my $AdaSim_csv_fh, ">", $outFile or die "$outFile: $!";
   
    #print header
    print $AdaSim_csv_fh "# Gmail2AdaSIM\n";
    print $AdaSim_csv_fh "# \"Name\", Number\n";
   
    my $memNumber=1;
   
   while (my $hr = $gmail_csv->getline_hr ($gmail_csv_fh))
   { 
      my $mobileNum;          
             
             for(my $i=1;$i< @headerNames;$i++)
             {
                #print $allKeys[$i] . "\n";
                if($hr->{$headerNames[$i]} eq "Mobile")
                  {
                     
                    $hr->{$headerNames[$i+1]} =~ s/[\(|\)|-]//g ;
                $hr->{$headerNames[$i+1]} =~ s/-/ /g ;

               
                     my($mobileNum ) = $hr->{$headerNames[$i+1]} =~ m/^([\+|\d|\s]*)/ ;
                     print $hr->{$headerNames[0]} .":". $mobileNum . "\n";
                     print $AdaSim_csv_fh "\"" . substr($hr->{$headerNames[0]},0,17) ."\"," . substr($mobileNum,0,19) . "\n";
                     $i = @headerNames + 1;
                  }
             } 
       $memNumber++;
    }  #while
    $memNumber--;
    print "Conversion complete!.\n  Converted $memNumber line(s);\n  Output in file: $outFile\n";

rabbitnyc
 
Posts: 1
Joined: Mon Sep 13, 2010 8:56 pm

Gmail contacts to AdaFruit SIM loader format

by earlagd on Sun Sep 30, 2012 2:46 am

I just installed Outlook 2010 on my computer. I cannot import my Gmail contacts. I export them onto my desktop but get an error message when I attempt to import. I have had the same problem when I have attempted to import contacts from Windows Live Mail. Any suggestions? Thanks
User avatar
earlagd
 
Posts: 1
Joined: Tue Sep 18, 2012 11:30 am
Location: United States