-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiphone_contacts.pl
64 lines (47 loc) · 2.56 KB
/
iphone_contacts.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env perl
use strict;
use DBI;
use SQL::Abstract;
use Numbski;
my $numbski = Numbski->new(
'path' => '/home/shadwickt/Desktop/contacts.csv',
);
my $database_handle = DBI->connect("dbi:SQLite:dbname=/home/shadwickt/Desktop/AddressBook.sqlitedb","","");
my $sql = SQL::Abstract->new;
my($person_statement,@person_bind) = $sql->select('ABPerson',['ROWID','First','Last','Organization','Note','Kind','JobTitle','Nickname']);
my $person_sth = $database_handle->prepare($person_statement);
$person_sth->execute(@person_bind);
#my($multivalueentry_statement,@multivalueentry_bind) = $sql->select('ABMultiValueEntry');
#my $multivalueentry_sth = $database_handle->prepare($multivalueentry_statement);
#$multivalueentry_sth->execute(@multivalueentry_bind);
my($multivalue_statement,@multivalue_bind) = $sql->select('ABMultiValue');
my $multivalue_sth = $database_handle->prepare($multivalue_statement);
$multivalue_sth->execute(@multivalue_bind);
#my($multivalueentrykey_statement,@multivalueentrykey_bind) = $sql->select('ABMultiValueEntryKey');
#my $multivalueentrykey_sth = $database_handle->prepare($multivalueentrykey_statement);
#$multivalueentrykey_sth->execute(@multivalueentrykey_bind);
#my($multivaluelabel_statement,@multivaluelabel_bind) = $sql->select('ABMultiValueLabel');
#my $multivaluelabel_sth = $database_handle->prepare($multivaluelabel_statement);
#$multivalueelabel_sth->execute(@multivaluelabel_bind);
my $csv = "First,Last,Organization,Home,Work,Mobile,Other,Homepage,Main,Fax\n";
my @people;
while(my $hash = $person_sth->fetchrow_hashref()){
$people[$hash->{'ROWID'}]->{'first'} = $hash->{'First'};
$people[$hash->{'ROWID'}]->{'last'} = $hash->{'Last'};
$people[$hash->{'ROWID'}]->{'organization'} = $hash->{'Organization'};
#$people[$hash->{'ROWID'}]->{'organization'} =~ s/,/\\,/g;
}
#my @multi_key;
#while(my $hash = $multivalueentrykey_sth->fetchrow_hashref()){
# push(@multi_key,$hash->value);
#}
my @multi_label = ('other','home','mobile','work','homepage','main','fax');
while(my $hash = $multivalue_sth->fetchrow_hashref()){
$people[$hash->{'record_id'}]->{$multi_label[$hash->{'label'}]} = $hash->{'value'};
}
foreach my $person(@people){
print "Working on $person->{'first'} $person->{'last'}\n";
$csv .= "\"$person->{'first'}\",\"$person->{'last'}\",\"$person->{'organization'}\",\"$person->{'home'}\",\"$person->{'work'}\",\"$person->{'mobile'}\",\"$person->{'other'}\",\"$person->{'homepage'}\",\"$person->{'main'}\",\"$person->{'fax'}\"\n";
}
$numbski->contents($csv);
$numbski->write_file;