Created
January 31, 2011 19:28
-
-
Save jdudek/804632 to your computer and use it in GitHub Desktop.
Convert Opera's .adr address book to CSV
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
# ruby 1.9.2 | |
require "csv" | |
File.open("contacts2.adr", "r") do |f| | |
contacts = [] | |
f.read.split("#CONTACT").each do |entry| | |
unless entry.empty? | |
contact = {} | |
entry.each_line do |line| | |
unless line.empty? | |
k, v = line.strip.split("=") | |
contact[k] = v | |
end | |
end | |
contacts << contact | |
# p contact | |
end | |
end | |
str = CSV.generate do |csv| | |
csv << %w(name email phone) | |
contacts.each do |contact| | |
csv << [contact["NAME"], contact["MAIL"], contact["PHONE"]] | |
end | |
end | |
puts str | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just what I needed, thanks for sharing. Note: I replaced
puts str
withFile.write("contacts.csv", str)