<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
  <title type="html">Connotea To Del.icio.us</title>
  <link href="http://benlund.info/2007/01/30/contodel" rel="alternate"/>
  <link href="http://benlund.info/2007/01/30/contodel/atom" rel="edit"/>
  <id>http://benlund.info/2007/01/30/contodel</id>
  <updated>2007-01-30T22:34:57Z</updated>
  <published>2007-01-30T22:34:57Z</published>
  <author>
    <name>Ben Lund</name>
  </author>
  <category term="web_development" label="Web Development"/>
  <category term="main" label="Front Page"/>
  <summary type="html">

    &amp;lt;p&amp;gt; I wanted to import all my &amp;lt;a href=&amp;quot;http://www.connotea.org/user/ben&amp;quot;&amp;gt;Connotea bookmarks&amp;lt;/a&amp;gt; into &amp;lt;a href=&amp;quot;http://del.icio.us/benlund&amp;quot;&amp;gt;my Del.icio.us account&amp;lt;/a&amp;gt; for a small experiment I was running. So I glued together the two APIs with a simple Ruby script. &amp;lt;/p&amp;gt;

    </summary>
  <content type="xhtml">
    <div xmlns="http://www.w3.org/1999/xhtml">

      <p> I wanted to import all my <a href='http://www.connotea.org/user/ben'>Connotea bookmarks</a> into <a href='http://del.icio.us/benlund'>my Del.icio.us account</a> for a small experiment I was running. So I glued together the two APIs with a simple Ruby script. </p>
<p> The script uses the <a href='http://ridiculous.rubyforge.org/'>Ridiculous</a> wrapper for the <a href='http://del.icio.us/help/api/'>Del.icio.us API</a> and my own <a href='http://www.connotea.org/wiki/WWWConnoteaRuby'>www-connotea-ruby</a> for the <a href='http://www.connotea.org/wiki/WebAPI'>Connotea Web API</a>. </p>
<p> I had problems installing Ridiculous from Rubygems, so I pulled it down from the SVN repository <pre>
    $ svn co svn://rubyforge.org//var/svn/ridiculous/0.5
  </pre> I had to patch ridiculous.rb with <a href='/static/ridiculous_v05_patch.patch'>this</a>. </p>
<p> I <a href='http://prdownloads.sourceforge.net/connotea/www-connotea-ruby-0.1.tar.gz?download'>downloaded www-connotea-ruby</a> and extracted it <pre>
    $ tar xvzf www-connotea-ruby-0.1.tar.gz
  </pre> And the connecting glue was just a few lines: </p>
<div class='code'><pre>
<span class='comment-delimiter'>#</span><span class='comment'>!/usr/bin/env ruby
</span>
<span class='comment-delimiter'># </span><span class='comment'>contodel.rb
</span><span class='comment-delimiter'># </span><span class='comment'>by Ben Lund, Jan 2007
</span>
<span class='comment-delimiter'># </span><span class='comment'>Usage: ruby contodel.rb connotea_username:connotea_password delicious_username:delicious_password
</span>
require <span class='string'>&#39;0.5/ridiculous&#39;</span>
require <span class='string'>&#39;www-connotea-ruby-0.1/lib/www/connotea&#39;</span>

c_user, c_pass = *<span class='type'>ARGV</span>.shift.split(<span class='string'>/:/</span>)
<span class='type'>Ridiculous</span>::<span class='type'>USERNAME</span>, <span class='type'>Ridiculous</span>::<span class='type'>PASSWORD</span> = *<span class='type'>ARGV</span>.shift.split(<span class='string'>/:/</span>)

c = <span class='type'>WWW</span>::<span class='type'>Connotea</span>.new(<span class='constant'>:user</span> =&#62; c_user, <span class='constant'>:password</span> =&#62; c_pass)

c.posts_for(<span class='constant'>:user=</span>&#62; c_user) <span class='keyword'>do</span> |p|
  success = <span class='variable-name'>false</span>
  <span class='keyword'>begin</span>
    success = <span class='type'>Ridiculous</span>::<span class='type'>Post</span>.new.add(
      <span class='constant'>:url</span> =&#62; p.link,
      <span class='constant'>:description</span> =&#62; p.title || p.link,
      <span class='constant'>:extended</span> =&#62; p.description,
        <span class='comment-delimiter'># </span><span class='comment'>Convert multi-word tags to underscore-separated</span>
        <span class='comment-delimiter'># </span><span class='comment'>And convert all to lowercase to overcome case-insensitivity 
  </span>
      <span class='constant'>:tags</span> =&#62; p.tags.map{|t| t.gsub(<span class='string'>/\s+/</span>, <span class='string'>&#39;_&#39;</span>).downcase }.join(<span class='string'>&#39; &#39;</span>) )
  <span class='keyword'>end</span>
  <span class='keyword'>raise</span> <span class='string'>&#34;Couldn&#39;t post </span><span class='variable-name'>#{p.link}</span><span class='string'>&#34;</span> <span class='keyword'>unless</span> success

  <span class='comment-delimiter'>#</span><span class='comment'>give the del.icio.us server a rest</span>
  sleep(1)
<span class='keyword'>end</span>
</pre></div>
<p class='update'> Update: Via <a href='http://www.ghastlyfop.com/blog/2007/02/delicious-to-connotea-mk2.html'>Stew</a>, a <a href='http://www2.informatik.hu-berlin.de/%7Ebaierer/src/diu2con.pl'>script</a> to go back the other way from <a href='http://www2.informatik.hu-berlin.de/%7Ebaierer/projekte.php'>Konstantin Baierer</a>. </p>
        </div>
  </content>
</entry>
