from xml.dom import minidom import urllib2, base64 user = 'username' passwd = 'password' mindmap = open(user+'.mm', 'w') mindmap.write('\n') mindmap.write('\n') mindmap.write('\n' % ( user, user )) def auth_open(url): request = urllib2.Request(url) base64string = base64.encodestring('%s:%s' % (user,passwd))[:-1] request.add_header("User-Agent", "delicious_mind") request.add_header("Authorization", "Basic %s" % base64string) return urllib2.urlopen(request) recent_post_data = auth_open('http://del.icio.us/api/posts/recent?count=100').read() posts = minidom.parseString(recent_post_data).documentElement.getElementsByTagName("post") tag_data = auth_open('http://del.icio.us/api/tags/get?').read() xdoc = minidom.parseString(tag_data).documentElement for tag in xdoc.getElementsByTagName("tag"): category = tag.getAttribute("tag") mindmap.write('\n' % ( user, category, category )) for post in posts: if post.getAttribute("tag").find(category) != -1: mindmap.write('\n' % ( post.getAttribute("href").encode('ascii', 'xmlcharrefreplace').replace('&', '&'), post.getAttribute("description").encode('ascii', 'xmlcharrefreplace').replace('"','"').replace('&', '&'))) mindmap.write('\n') mindmap.write('\n\n')