Skip to content

Instantly share code, notes, and snippets.

@ngn999
Last active August 29, 2015 14:15
Show Gist options
  • Save ngn999/96737a1b8fa8c3705566 to your computer and use it in GitHub Desktop.
Save ngn999/96737a1b8fa8c3705566 to your computer and use it in GitHub Desktop.
convert ontacts.xml iCloud.vcf
#!/usr/bin/env perl
use strict;
use Text::vCard::Addressbook;
use XML::Simple qw(:strict);
use Data::Dumper;
my $address_book = new Text::vCard::Addressbook;
my $doc = XMLin('./contacts.xml', KeyAttr => { }, ForceArray => [ 'people', 'phone' ]);
foreach my $p (@{$doc->{people}}) {
next unless ((exists $p->{'phones'}) and (@{$p->{'phones'}->{'phone'}} > 0));
my $vcard = $address_book->add_vcard;
$vcard->version('3.0');
$vcard->PRODID('-//Apple Inc.//iOS 8.1//EN');
$vcard->REV('2014-12-12T09:57:34Z');
$vcard->fullname($p->{'familyname'}.$p->{'givenname'}); # required field
my $address = $vcard->add_node({'node_type'=>'moniker',});
$address->family($p->{'familyname'});
$address->given($p->{'givenname'});
my $tels = $vcard->add_node({'node_type'=>'TEL',});
$tels->add_types('work');
$tels->value($p->{'phones'}->{'phone'}->[0]->{"content"});
}
open my $out, '>:encoding(UTF-8)', 'new_address_book.vcf' or die;
print $out $address_book->export;
close $out;
@ngn999
Copy link
Author

ngn999 commented Feb 10, 2015

联系人没有存在sim卡里,原先的android机器进水了,还好刷机时用刷机精灵备份过,用Perl转成iCloud能识别的vCard格式,从icloud.com导进去。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment