-
-
Save rickychilcott/2906dfed3add69f1cb9c771d6d56438c to your computer and use it in GitHub Desktop.
Get a csv from an Apple Address Book ".abbu" archive
This file contains 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
require 'csv' | |
require 'pry' | |
# sqlite3 AddressBook-v22.abcddb | |
# .headers on | |
# .mode csv | |
# .output ZABCDPOSTALADDRESS.csv | |
# select * from ZABCDPOSTALADDRESS; | |
# .mode csv | |
# .output ZABCDRECORD.csv | |
# select * from ZABCDRECORD; | |
address_filename = "ZABCDPOSTALADDRESS.csv" | |
record_filename = "ZABCDRECORD.csv" | |
# binding.pry | |
addresses = {} | |
CSV.read(address_filename, headers: true).entries.map(&:to_hash).map{|h| | |
addresses[h["ZOWNER"]] = { | |
city: h["ZCITY"], | |
state: h["ZSTATE"], | |
street: h["ZSTREET"], | |
zip: h["ZZIPCODE"] | |
} | |
h | |
}; nil | |
people = [] | |
CSV.read(record_filename, headers: true).entries.map(&:to_hash).each{|h| | |
# binding.pry | |
address = addresses[h["Z_PK"]] | |
if address | |
address = "#{address[:street]}, #{address[:city]} #{address[:state]} #{address[:zip]}" | |
end | |
people << { | |
name: "#{h["ZLASTNAME"]} #{h["ZMIDDLENAME"]} #{h["ZLASTNAME"]}", | |
address: address | |
} | |
}; nil | |
class Array | |
def to_csv(csv_filename="hash.csv") | |
require 'csv' | |
CSV.open(csv_filename, "wb") do |csv| | |
csv << first.keys # adds the attributes name on the first line | |
self.each do |hash| | |
csv << hash.values | |
end | |
end | |
end | |
end | |
people.to_csv('people.csv') | |
# binding.pry |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a start...
Find all files that have AddressBook-v22.abcddb, crawl through them and do a query like:
Look in the following tables
zabcdemailaddress
andzabcdrecord
pluck
z_pk
,zlastname
,zfirstname
fromzabcdrecord
and merge it with
zowner
,zaddress
fromzabcdemailaddress
Take those and store them...