multipart-message nevyn bengtsson's blog

featured articles 🦄, about, archive, tags

Py vs rb: Round 8451

My brother sent me a vcard file and asked if I could extract its email adresses somehow (some 1500 of them). Started out with a regexp but it just made my head hurt, so I thought, “Hey, I could do this faster with a script” and googled for “python vcard”. Found vobject, spent half an hour trying to find samples and trying to make heads or tails of the documentation (don’t click if you don’t like migraine), but finally just gave up (I was in lazy-sunday mode and just skimmed the page and docus; imo, more shouldn’t be needed for such a simple task). Try two, googled “ruby vcard” and found vpim (note the ‘excessive’ amount of excellent samples). A “gem install vpim” and less than two minutes in TextMate gave me:


require 'rubygems'
require 'vpim/vcard'

cards = Vpim::Vcard.decode(open("/Users/nevyn/Desktop/vCard-kort.vcf"))

cards.each do |card|
    puts "#{card.email}"
end

I liked Python when I started learning it years ago, but I just can’t stand it anymore. I know it’s just a library, but I’ve had many such experiences with Python. And it doesn’t have proper blocks! Gah.

Tagged