Happy Arduino Day! Use the code ARDUINODAY on checkout and get 10% off your order on all items in stock!

Gmail contacts to AdaFruit SIM loader format
Moderators: adafruit_support_bill, adafruit

Gmail contacts to AdaFruit SIM loader format

by rabbitnyc on Mon Sep 13, 2010 10: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.


Code: Select all | TOGGLE FULL SIZE

#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";
   "example usage:"."\n".
   "perl Gmail2AdaSIM.pl google.csv gmail2AdaSim.csv"."\n"

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;
    }  #while
    print "Conversion complete!.\n  Converted $memNumber line(s);\n  Output in file: $outFile\n";

Posts: 1
Joined: Mon Sep 13, 2010 9:56 pm

Gmail contacts to AdaFruit SIM loader format

by earlagd on Sun Sep 30, 2012 3: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
Posts: 1
Joined: Tue Sep 18, 2012 12:30 pm
Location: United States