Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get a csv from an Apple Address Book ".abbu" archive
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
@rickychilcott
Copy link
Author

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 and zabcdrecord

pluck z_pk,zlastname, zfirstname from zabcdrecord
and merge it with zowner,zaddress from zabcdemailaddress

Take those and store them...

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