Chris Schmidt (crschmidt) wrote,
Chris Schmidt

Del.Icio.Us Bookmarks + LiveJournal

So, my ex-roomate has his bookmarks integrated into his website. He uses Drupal, and simply takes his aggregated feed and passes it into his sidebar - trivially simple in Drupal. I wanted the same functionality for my LiveJournal, because I'm always competing to show how LiveJournal, using S2, can be a very powerful tool for personal publishing.

I knew that S2 had an interface for uploading layers through a protocol - but I'd never taken advantage of it before, because it uses Digest Authentication - something I've never worked with, and didn't really know how to work with. The simple script that Mart provided wouldn't work for it, simply because that script was designed to support Basic Auth and not Digest.

However, I was really interested in writing something that would let me edit S2 layers from the command line, rather than using the Web Interface for it.

First, I wrote support in my main layout layer for a function called "lay_print_bookmarks". This function doesn't do anything in the layout layer: similar to print_custom_head, it is designed to be overridden by the theme layer. In my layer, I call lay_print_bookmarks, which is the function which prints them out. Remember, in S2, layers are hierarchically put together: user layer overrides theme layer overrides layout layer overrides core layer. So, my theme layer changes will override my layout layer.

Next, I needed to get the content I wanted from The site provides a simple api from which you can get your recent bookmarks. On my machine, I have a script called lwp-request (I'm pretty sure it came as part of a Perl package I installed at some point) which can download pages, including those which require authentication via either Basic or Digest Auth. I had never heard of this until today, so I was pleased to see everything done so easily for me.

Next, I set myself up with a sed script to replace the post format that delicious uses (<post time="2004-04-30T14:09:39Z" href="" tag=" system:unfiled" description="Department of Computer Science" extended="Siebel center homepage"/>) with a linkable format, in the form of an HTML list. I first grep to find lines that contain the bookmarks, then spit out <li><a>link</a><li> formatted links.

lwp-request -C crschmidt:deliciouspassword | grep "<post " | sed -e 's/.*href="\([^"]*\)".*description="\([^"]*\)".*/<li><a href="\1">\2<\/a><\/li>/'` >> /tmp/bookmarks.tmp

Great! Now I have my bookmarks in a simple format which I can copy paste into an S2 file!

But that's not enough for me. Next, I have to figure out how to send the code to LiveJournal - this should be something that I can use completely non-interactively, if I choose.

So, I figure out that I can use lwp-request with a method of PUT and put my S2 layer online using the same method!

lwp-request -m PUT -c application/x-danga-s2-layer -C crschmidt:ljpassword < /tmp/bookmarks.tmp

Suddenly my theme layer is populated! I have once again conqured the day! and every hour, my bookmarks will be updated to that which I have on Del.Icio.Us. And to me, that's just cool.

echo "layerinfo \"type\" = \"theme\";
layerinfo \"name\" = \"Bookmarks\";
function lay_print_bookmarks(){
echo `lwp-request -C crschmidt:deliciouspassword | grep "<post " | sed -e 's/.*href="\([^"]*\)".*description="\([^"]*\)".*/<li><a href="\1">\2<\/a><\/li>/'` >> /tmp/bookmarks.tmp
echo "</ul>\"\"\";
<ul>"> /tmp/bookmarks.tmp
}" >> /tmp/bookmarks.tmp
lwp-request -m PUT -c application/x-danga-s2-layer -C crschmidt:ljpassword < /tmp/bookmarks.tmp

  • candy

    At our old house, we always ran out of candy, so I live in perpetual fear of it. At this house, we were totally ghost town one year, and we ran out…

  • Projects

    Overall, I have a handful of projects I'm working on. - Livestream Alerts: Website for generating alerts during Livestreams. Most recent work:…

  • sigh, humans

    For the last 36 hours, I have been unreasonably upset by the simplest, stupidest things that people do. Why can't people just be more smart and less…

  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded