Gmail contacts to AdaFruit SIM loader format

Talk about the videos and projects (SIM reader, payphones...)

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
gustavvr
 
Posts: 1
Joined: Mon Sep 13, 2010 9:56 pm

Gmail contacts to AdaFruit SIM loader format

Post by gustavvr »

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

#!/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";


earlagd
 
Posts: 1
Joined: Tue Sep 18, 2012 12:30 pm

Gmail contacts to AdaFruit SIM loader format

Post by earlagd »

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

Locked
Please be positive and constructive with your questions and comments.

Return to “Citizen Engineer (closed)”