Created
December 14, 2019 16:57
-
-
Save tsukkee/785707768a1117d139e728461be1ec9f to your computer and use it in GitHub Desktop.
macOSの連絡先.appから書き出したvCardをみてね年賀状用のCSVに加工する。 vcard2mitene.rb hoge.vcf | iconv -f utf8 -t cp932 > hoge.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
require 'vcard' | |
require 'nkf' | |
file = open(ARGV[0], 'r') | |
vcard = Vcard::Vcard.decode(file) | |
def to_hiragane(katakana) | |
NKF.nkf('-w --hiragana', katakana) | |
end | |
vcard.each do |v| | |
puts [ | |
v.name.family, | |
v.name.given, | |
to_hiragane(v['X-PHONETIC-LAST-NAME']), | |
to_hiragane(v['X-PHONETIC-FIRST-NAME']), | |
v.name.suffix.empty? ? '様' : v.name.suffix, | |
v.address.postalcode.delete('-'), | |
v.address.region, | |
v.address.locality, | |
v.address.street.split(/([\da-zA-Z-]+$)/).join(', '), | |
'', | |
v.values('X-ABRELATEDNAMES').map{|r| | |
['', r, '様'].join(', ') | |
}.join(', ') | |
].join(', ') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment