Ruben Laguna's blog

Aug 8, 2009 - 2 minute read - bookmarks delicious evernote html htmlentities import mac note ruby rubyosa scripting

Import delicious bookmarks into Evernote

I tried to use the delicious online import tool from Evernote and I have to say that I’m not satisfied with it. It’s limited to 1000 tags (that’s due to important performance issues in Evernote when the number of tags is big) and if you don’t import the tags the tag information is lost.

I was expecting that it will add the delicious tags and link notes as body text in the Evernote note but they don’t. So I decided to do my own import to preserve that information.

That’s how bookmarks look like when using the online tool provided by Evernote:

My tool uses a delicious backup in Netscape Bookmarks file format created with in delicious with “Settings ⇒ Export/Backup bookmarks” as input. And uses the Mac Scripting for Evernote to create notes in a local notebook named del2 (that has to be previously created).

The delicious bookmarks looks like this once they are imported to evernote

Here is the ruby script (also as a gist) that I used to do the import (note that you need to install rubyosa on htmlentities gems prior to use:

#!/usr/bin/ruby -w
require "rubygems"
require "rbosa"
require "cgi"
require "htmlentities"
require 'iconv'

OSA.utf8_strings = true
evernote = OSA.app('Evernote')
coder = HTMLEntities.new

i=1
url = nil
add_date = nil
title = nil
last_visit = nil
tags = nil
notes = ""
File.new("delicious-20090807.htm").each{|line|
  #next unless i >2261

  if line =~ /<DT><A HREF="(.*)" LAST_VISIT="(.*)" ADD_DATE="(.*)" TAGS="(.*)">(.*)<\/A>$/
    if url
      #puts "#{i} url:#{url} add:#{Time.at(add_date.to_i)} last:#{Time.at(last_visit.to_i)} tags:#{tags} title:#{title} notes:#{notes}"
      #title = CGI.escapeHTML(title)
      #notes = CGI.escapeHTML(notes)
      #titleunencoded = Iconv.conv("UTF-8","ISO-8859-1",title)
      titleunencoded = title[0,254]
      title = coder.encode(title,:named)
      notes = coder.encode(notes,:named)
      tags = coder.encode(tags,:named)
      body = "h1. #{title}
      body += "p. <a href=\"#{url}\">#{title}</a>
      body += "h2. tags
      body += "p. #{tags}
      body += "h2. description and notes
      body += "p. #{notes}
      body += "h2. dates
      body += "p. add date: #{Time.at(add_date.to_i)}
      body += "p. last visit date: #{Time.at(last_visit.to_i)}
      puts body
      notehandle = evernote.create_note(:with_html => body, :title => titleunencoded, :notebook => "del2" )
      notehandle.source_url = url

      i += 1
      url,last_visit,add_date,tags,title,notes = nil,nil,nil,nil,nil,""
    end
    url,last_visit,add_date,tags,title = $1, $2, $3, $4, $5
  else
    notes += line unless url.nil?
  end
}