Post categories



Recommended Wordpress Hosting from WPEngine

  • I use these guys for some of my clients; absolutely rock solid and blazingly fast - check them out!





Here are a couple of ads whose clicks and views help me pay for my server hosting











How to import your ReadItLater items into Delicious (python converter)

Posted on: 1 Comment

I like readitlater; but recently I found myself wanting to share some of my tagged items with other people and couldn’t find a way to do it. I used Delicious years ago and that’s always been a much more social app, so fired that up, and looked for way to import items.

Unfortunately the export format of readitlater isn’t compatible with the import format required by Delicious; so here’s a quick python script to convert a ReadItLater exported html file to a file that Delicious’s import will accept.

Get the export

First, visit readitlaterlist.com/export and download that file somewhere; it should create ril_export.html

Convert to Delicious format

Copy the script below to ril2del.py (or whatever you feel like) then run:

./ril2del.py ril_export.html converted_for_delicious.html

Import to Delicious

Then visit the Delicious import page at export.delicious.com/settings/bookmarks/import and point it at your generated file (converted_for_delicious.html) and hey presto, you’ve got all your readitlater bookmarks in Delicious complete with tags. Read items from RiL will have an extra tag “read” and unread items have an “unread” tag.

The script

(requires python2 and BeautifulSoup4 to be installed; you can install BeautifulSoup4 with pip)

#!/usr/bin/env python

from bs4 import BeautifulSoup
import sys
import os

def usage():
    print "r2d <inputfile> <outputfile>"
    return 1

def first_child(list):
    for item in list:
        return item

def process(ul, extraTag, output):
    for li in ul.find_all("li"):
        a = li.a
        replacements = dict()
        replacements[":tags"] = a["tags"] + "," + extraTag
        replacements[":time_added"] = a["time_added"]
        replacements[":href"] = a["href"]
        replacements[":content"] = first_child(a)
        outputString = """<DT><A HREF=":href" ADD_DATE=":time_added" PRIVATE="1" TAGS=":tags">:content</A>\n"""
        for key in replacements:
            outputString = outputString.replace(key, replacements[key])
        output.write(outputString.encode("UTF-8"))

def main():
    args = sys.argv[1:]
    if len(args) != 2:
        return usage()
    infile = args[0]
    outfile = args[1]
    if not os.path.isfile(infile):
        print "Cannot read input file:", infile
    soup = BeautifulSoup(file(infile).read())

    output = file(outfile, "w")
    output.write("""<!DOCTYPE NETSCAPE-Bookmark-file-1>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<TITLE>Bookmarks</TITLE>
<H1>Bookmarks</H1>
<DL><p>
""")

    uls = soup.find_all("ul")
    unread = uls[0]
    read = uls[1]
    process(ul=unread, extraTag="unread", output=output)
    process(ul=read, extraTag="read", output=output)

    output.write("</DL><p>")

if __name__ == "__main__":
    sys.exit(main())