W-ZERO3のアドレス帳をFOMAのデータリンクソフト用に変換

概要

ソースコード

$fin = "W03.csv";
$fout = "FOMA.csv";

# メモリ番号の最初の値
$MemoryNo = 10;

@TelKeys =( 
	"BusinessTelephoneNumber", "BusinessFaxNumber", "CompanyTelephoneNumber", 
	"MobileTelephoneNumber", "HomeTelephoneNumber", "Home2TelephoneNumber", 
);

@EMailKeys = (
	"Email1Address", "Email2Address", "Email3Address", 
);

%Icon =(
	"BusinessTelephoneNumber" => 3, "BusinessFaxNumber" => 4, "CompanyTelephoneNumber" => 3,
	"MobileTelephoneNumber" => 1, "HomeTelephoneNumber" => 2, "Home2TelephoneNumber" => 2, 
	"Email1Address" => 24, "Email2Address" => 24, "Email3Address" => 24, 
);

open( IN, $fin ) || die( "can't open'".$fin."'.\n" );
open( OUT, ">".$fout ) || die( "can't open'".$fout."'.\n" );

$line = <IN>;
chop( $line );
@fields = split( ",", $line );
@addr_in = <IN>;
close( IN );
chop( @addr_in );

for( $i=0; $i<@addr_in; ++$i ){
	@addr_tmp = split( ",", $addr_in[ $i ] );
	%addr_out = ();
	for( $j=0; $j<@fields; ++$j ){
		if ( $addr_tmp[ $j ] =~ /^"(.*)"$/ ){
			$addr_tmp[ $j ] = $1;
		}
		$addr_out{ $fields[ $j ] } = $addr_tmp[ $j ];
	}

	$Name = $addr_out{ "FileAs" };
	$Yomi = $addr_out{ "YomiLastName" }.$addr_out{ "YomiFirstName" };
	$Group = "0";
	$Secret = "0";
	$PostalCode = $addr_out{ "BusinessAddressPostalCode" };
	$Addr = $addr_out{ "BusinessAddressState" }.$addr_out{ "BusinessAddressCity" }.$addr_out{ "BusinessAddressStreet" };
	$Memo = $addr_out{ "CompanyName" };
	if ( $addr_out{ "Birthday" } ne "" ){
		$Birthday = "19".$addr_out{ "Birthday" };
	}
	$step = 0;
	foreach $telkey ( @TelKeys ){
		$addr_out{ $telkey } =~ tr/-() //d;
		if ( $addr_out{ $telkey } ne "" ){
			printf OUT ( 
				"\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\"\n", 
				$MemoryNo+$i+$step, $Name, $Yomi, $addr_out{ $telkey }, $Group, $Icon{ $telkey }, 
				$Secret, "", $PostalCode, $Addr, $Memo, $Birthday
			);
			$step += 700;
		}
	}
	$step = 2800;
	foreach $emailkey ( @EMailKeys ){
		if ( $addr_out{ $emailkey } ne "" ){
			printf OUT ( 
				"\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\"\n", 
				$MemoryNo+$i+$step, $Name, $Yomi, "", $Group, $Icon{ $emailkey }, 
				$Secret, $addr_out{ $emailkey }, $PostalCode, $Addr, $Memo, $Birthday
			);
			$step += 700;
		}
	}

}

close( OUT );

# EOF

アイコン番号

0固定電話
1携帯電話
2自宅電話
3会社電話
4会社FAX
24一般メール
25自宅メール
26会社メール
27携帯メール

リロード   新規 下位ページ作成 編集 凍結 差分 添付 コピー 名前変更   ホーム 一覧 検索 最終更新 バックアップ リンク元   ヘルプ   最終更新のRSS
Last-modified: Sun, 04 Dec 2011 19:22:20 JST (2236d)