Pages

Wednesday, July 12, 2006

del.icio.us importing

I wanted to change my del.icio.us username. You aren't allowed to do this directly, but you can export your links to an html file and try to import it back into a new account. Unfortunately their import function can't parse the data generated by their export function. Strange. (apparently fixed now) Luckely they have an open API (and a whole bunch of third-party tools).

So with the help of BeautifulSoup I simply parsed the exported html and used pydelicious to post it back into delicious. Like So:

from BeautifulSoup import BeautifulSoup
import pydelicious
from itertools import count

def main():
soup = BeautifulSoup(file("export.htm").read())
user = "user"
password = "pass"
items = soup.findAll("a")
print len(items)
for item, n in zip(items, count()):
href = item["href"]
tags = item["tags"]
title = item.string
add_date = item["add_date"]
last_modified = item["last_modified"]
print n,
try:
pydelicious.add(user, password, href, title, tags=tags, dt=add_date, replace="yes")
except Exception, e:
print e

Ah, I love Python.

While writing this post I ran into some del.icio.us experiments, which might be useful to someone. And a follow-up with very pretty graphs.

1 comment:

Anonymous said...

Hi! I know this is an old post, but just a note: we fixed the import & export functions on del.icio.us so you should be able to transfer your bookmarks now without having to do all this. (We're sorry it was a little broken there for a while.)