from xml.dom import minidom import urllib2, base64 user = 'username' passwd = 'password' rdf = open(user+'.rdf', 'w') rdf.write('\n') rdf.write('\n') rdf.write('\n' % user) rdf.write('del.icio.us page for %s\n' % user) rdf.write('\n') rdf.write('\n') def auth_open(url): request = urllib2.Request(url) base64string = base64.encodestring('%s:%s' % (user,passwd))[:-1] request.add_header("User-Agent", "delicious_rdf v.1") 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() # With a prefetched file #recent_post_data = open('recent.xml').read() posts = minidom.parseString(recent_post_data).documentElement.getElementsByTagName("post") # This would be needed for RSS 1.0, but not for plain RDF. #rdf.write('\n') #for rdfli in posts: # rdf.write('\n' % ( # rdfli.getAttribute("href").encode('ascii', 'xmlcharrefreplace').replace('&', '&'))) #rdf.write('\n\n') for post in posts: rdf.write('\n' % ( post.getAttribute("href").encode('ascii', 'xmlcharrefreplace').replace('&', '&'))) rdf.write('%s\n' % ( post.getAttribute("description").encode('ascii', 'xmlcharrefreplace').replace('"','"').replace('&', '&'))) rdf.write('%s\n' % (user)) desc = post.getAttribute("extended").encode('ascii', 'xmlcharrefreplace').replace('"','"').replace('&', '&') if desc != "": rdf.write('\n%s\n\n' % (desc)) rdf.write('\n%s\n\n' % ( post.getAttribute("time").encode('ascii', 'xmlcharrefreplace').replace('"','"').replace('&', '&'))) tags = post.getAttribute("tag").split() for tag in tags: rdf.write('%s\n' % (tag)) rdf.write('\n \n') for tag in tags: rdf.write(' \n' % (tag)) rdf.write(' \n\n') rdf.write('\n\n') rdf.write('\n')