Last active
August 29, 2015 14:15
-
-
Save ngn999/96737a1b8fa8c3705566 to your computer and use it in GitHub Desktop.
convert ontacts.xml iCloud.vcf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
联系人没有存在sim卡里,原先的android机器进水了,还好刷机时用刷机精灵备份过,用Perl转成iCloud能识别的vCard格式,从icloud.com导进去。