Skip to content

Instantly share code, notes, and snippets.

@fakechris
Created October 3, 2011 07:03
Show Gist options
  • Save fakechris/1258590 to your computer and use it in GitHub Desktop.
Save fakechris/1258590 to your computer and use it in GitHub Desktop.
Export delicious export html format from delicious API
from StringIO import StringIO
from lxml import etree
import time
XML_BEGIN = """
<!DOCTYPE NETSCAPE-Bookmark-file-1>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<!-- This is an automatically generated file.
It will be read and overwritten.
Do Not Edit! -->
<TITLE>Bookmarks</TITLE>
<H1>Bookmarks</H1>
<DL><p>
"""
XML_END = """
</DL><p><!-- fe03.secure.del.ac4.yahoo.net uncompressed/chunked Mon Sep 26 02:05:19 UTC 2011 -->
"""
ITEM = """<DT><A HREF="%s" ADD_DATE="%s" PRIVATE="%s" TAGS="%s">%s</A>"""
all = open("all.xml", "r").read()
t = etree.parse(StringIO(all))
posts = t.findall('//post')
result = XML_BEGIN
for p in posts:
tag = ",".join(p.get("tag").encode("utf-8").split(" "))
href = p.get("href").encode("utf-8")
description = p.get("description").encode("utf-8")
if p.get("private") == "yes":
private = 1
else:
private = 0
ts = int(time.mktime(time.strptime(p.get("time"), "%Y-%m-%dT%H:%M:%SZ")))
result += ITEM % (href, ts, private, tag, description)
result += XML_END
print result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment