Dr Nic

Exporting Netvibes bookmarks to Del.icio.us

For 12 months I’ve been using Netvibes to store bookmarks. A few weeks ago I started using Del.icio.us, which is also integrated into Netvibes. Now I had two sets of bookmarks. That’s one too many. Time to retire the Netvibes bookmark module, but how do I migrate/export the netvibes bookmarks, and how do I upload them to Del.icio.us?

“How to export Netvibes bookmarks?”

Exporting Netvibes bookmarks is a major request on their forum, so here is the answer.

  1. Login to Netvibes
  2. Go to address: http://www.netvibes.com/modules/bookmarks/getUserBookmarks.php?nocache=0
  3. Save the XML as netvibes_bm.xml

The XML should look something like:

<result>
  <link id="4401802" title=".htaccess generator" url="http://www.tools.dynamicdrive.com/password/" tags="unix"/>
  <link id="6444925" title="19 Rails Tricks Most Rails Coders Don't Know" url="http://www.rubyinside.com/19-rails-tricks-most-rails-coders-dont-know-131.html" tags="RoR"/>
  <link id="4436310" title="37signals - the tools we use ourselves" url="http://37signals.com/svn/archives2/the_tools_we_use_to_run_and_build_37signals.php" tags="business, ideas, RoR"/>
...
</result>

Note that your Netvibes tags are included. These will be uploaded into Del.icio.us too.

“How to upload Del.icio.us bookmarks?”

Now you are ready to upload these bookmarks into Del.icio.us (or modify it yourself to upload it wherever you want). I’ve written a script to do this using the Ruby programming language (dowload and install instructions here). Why? Because it took 10 minutes to do so. Feel free to rewrite it if you really want, but it’d be quicker to install Ruby, run the script, and move on with your life :)

  1. Install Ruby
  2. Install Hpricot [1]: type gem install hpricot (select the win32 version if you are on windows)
  3. Download the netvibes_delicious.rb script [2]
  4. Change the username and password values in the script to your del.icio.us username/password.
  5. Execute the script: ruby netvibes_delicious.rb netvibes_bm.xml
  6. The script will tell you how many bookmarks it will be uploading to Del.icio.us, and ask you to press return to continue. Press Ctrl-C to kill the script.

If you want to “test” the script first, create a copy of your netvibes_bm.xml file, and cut away all the <link ... > tags, except one or two. Check that the script works on these few bookmarks first, then rerun the script on the original file.

Now add the Del.icio.us module into Netvibes and remove the original Bookmarks module.

Tally ho.

[1] Hpricot is a brilliant library for parsing and processing HTML/XML data.

[2] The contents of the script:

['rubygems', 'hpricot', 'open-uri', 'net/https', 'cgi'].each {|lib| require lib}

# Netvibes bookmarks XML file
file = ARGV.shift
bookmarks = []

page = Hpricot(open(file))
page.search("//link").each do |link|
  bookmarks << {
    :title => link.get_attribute("title"),
    :description => link.get_attribute("title"),
    :url   => link.get_attribute("url"),
    :tags  => link.get_attribute("tags").split(', ').join(" "),
    :shared => "yes"
  }
end

puts "Transferring #{bookmarks.length} bookmarks to Del.icio.us"
puts "Do it?"; gets

# Del.icio.us target for bookmarks
username = "" # your del.icio.us username
password = "" # your del.icio.us password

resp = href = "";

bookmarks.each do |bookmark|
  begin
    http = Net::HTTP.new("api.del.icio.us", 443)
    http.use_ssl = true
    http.start do |http|
      pp bookmark
      req = Net::HTTP::Post.new("/v1/posts/add",
        {"User-Agent" => "drnicwilliams.com Netvibes to Delicious"})
      req.basic_auth(username, password)
      req.set_form_data bookmark
      response = http.request(req)
      resp = response.body
      puts "#{Hpricot(resp).search('/result').first.get_attribute('code').humanize} -> #{bookmark[:title]}"
    end     

  rescue SocketError
    raise "Host " + host + " not accessible"
  end
end

100s cheatsheets for Ruby and Rails

Ok, disclaimer. As of writing there aren’t exactly 100+ cheatsheets available on errtheblog‘s wonderful new cheatsheet tool, but its only a matter of time til my title is correct. Then I will rewrite this introduction paragraph and I will be the earliest dating author to declare how large and wonderful cheat is.

“What is cheat?” All your cheatsheets on the command line – where you are already working.

Check this out:

>cheat sprintf
sprintf:
  %s => string
  %d => number
  %f => float

>cheat strftime
strftime:

  %a - The abbreviated weekday name (``Sun'')
  %A - The  full  weekday  name (``Sunday'')
  %b - The abbreviated month name (``Jan'')
  %B - The  full  month  name (``January'')
  %c - The preferred local date and time representation
  %d - Day of the month (01..31)
  %H - Hour of the day, 24-hour clock (00..23)
  %I - Hour of the day, 12-hour clock (01..12)
  %j - Day of the year (001..366)
  %m - Month of the year (01..12)
  %M - Minute of the hour (00..59)
  %p - Meridian indicator (``AM''  or  ``PM'')
  %S - Second of the minute (00..60)
  %U - Week  number  of the current year,
          starting with the first Sunday as the first
          day of the first week (00..53)
  %W - Week  number  of the current year,
          starting with the first Monday as the first
          day of the first week (00..53)
  %w - Day of the week (Sunday is 0, 0..6)
  %x - Preferred representation for the date alone, no time
  %X - Preferred representation for the time alone, no date
  %y - Year without a century (00..99)
  %Y - Year with century
  %Z - Time zone name
  %% - Literal ``%'' character

   t = Time.now
   t.strftime("Printed on %m/%d/%Y")   #=> "Printed on 04/09/2003"
   t.strftime("at %I:%M%p")            #=> "at 08:56AM"

All your cheatsheets are now available via the console.

“All of them”? Yes, well no, but yes. The cheatsheets are written up on a public wiki, and thecheat command retrieves the requested text, caches it locally, and fills your ASCII virtual world with the cheatsheet. So, want to add another cheatsheet? Create a new wiki page, insert cheatsheet, save, done.

“But what cheatsheets are available? How do I know what I can get my dirty, cheating hands on?”

Watch, young reader, and gasp with amazement:

>cheat sheets
All Cheat Sheets:
  assertions
  bash
  cheat
  environments
  iomodes
  migrations
  sprintf
  sti
  strftime
  validations

To my thinking, cheat is a next-generation man tool. Instead of bundling manual pages with your application/gem/library, you could now host a set of live manual pages. Perhaps errtheblog or RubyForge could provide a separate wiki + command line for gem manual pages (hint: gemman or mangem)?

Lord, I love thy software industry.

Fixing your Feedburner feeds

Feedburner is great – you get snazzy graphs [1]. And other stuff. People use your feedburner link, instead of your raw RSS feed, in their feed reader and Feedburner will track your number of subscribers.

But it cannot track this information if your readers don’t use your Feedburner link. Why wouldn’t they use your Feedburner link? For two reasons:

  • You haven’t included the link on your blog sidebar (most people do this correctly)
  • You haven’t replaced the RSS links in your blog header (most people stuff this up)

Understand, there are two common ways for blog subscribers to add your site to their reader:

Unfortunately for many bloggers, if your readers use the latter method and you haven’t fixed your header (shown below), then they will be signing up for the raw RSS feed, and you’ll be none the wiser about them. They’ll be an invisible subscriber and won’t make your graphs as tall as they should be.

Let’s take an example of a broken blog and fix it for him. But, you can’t actually tell him to fix it otherwise I’ll have to update my example. Ad infinitum. So, its mum’s the word, ok? Only 180 subscribers on this blog – statistically he’s not one of them. Shhhh.

Visit the pinupgeek.com run by Rodney, where you’ll get weekly updates on the forum discussions of core improvements. On the right hand side, you’ll see the heading Subscribe and the RSS logo. The link under this logo is http://feeds.feedburner.com/pinupgeek – a Feedburner link. So we know he wants people to use his Feedburner link so he can watch his pretty graphs.

Now, right click on the page, and select “View Page source”. Note that in the header you’ll see the following:

  <link href="http://www.pinupgeek.com/xml/rss" rel="alternate" title="RSS" type="application/rss+xml" />

This link, of type application/rss+xml, will be used by RSS readers around the world automagically when passed a blog url, instead of an RSS feed link.

Here’s what happens in Netvibes for Rodney’s site:

Blog headers providing incorrect RSS feed link

No Feedburner link, just the raw RSS link (and a RSD feed link – what’s this for??).

So, let’s fix Rodney’s site.

Replace the above link with the following (using your blog’s theme editor):

  <link href="http://feeds.feedburner.com/pinupgeek" rel="alternate" title="RSS" type="application/rss+xml" />

If Rodney did this, then when I added his site into my Netvibes reader – or any other reader – I would automatically pick up his Feedburner link, and not his raw, unmonitored links.

In other words, his graph will get bigger.

[1] My blog is one month old and here is my Feedburner graph:

Feedburner - August 2006