On Fri, May 11, 2007 at 12:53:03PM +0200, Stephane Bortzmeyer <[EMAIL PROTECTED]> wrote a message of 337 lines which said:
> Yes, because, otherwise, you change the description and the other > tags. Not very convenient but it works. Python code attached for those > who are interested. > > > > [Non-text portions of this message have been removed] OK, Python code *included* to work around stupid MLM software: #!/usr/bin/python import urllib import urllib2 import cElementTree as ElementTree base_url = "https://api.del.icio.us/v1/posts" url_add = "%s/add" % base_url url_get = "%s/get" % base_url name = "billgates" password = "Too Secret" bookmark = "http://www.example.org/" def add_ua(request): request.add_header('User-Agent', "Test of adding a tag - [EMAIL PROTECTED]") password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm() password_manager.add_password( None, base_url, name, password) auth_handler = urllib2.HTTPBasicAuthHandler(password_manager) opener = urllib2.build_opener(auth_handler) urllib2.install_opener(opener) # Unfortunately, del.icio.us does not allow to just add a tag. We have # to retrieve the bookmark, add the tag and send it back :-( request = urllib2.Request(url_get + "?url=%s" % bookmark) add_ua(request) reply = urllib2.urlopen(request) xml = ElementTree.fromstring(reply.read()) post = xml.find("post") if post is None: raise Exception("No such bookmark %s" % bookmark) bookmark = post.attrib["href"] description = post.attrib["description"] tags = post.attrib["tag"] + " bork" # TODO: handle the case where bork is already # there. But del.icio.us seems to do it itself print """ Bookmark: %s Description: %s Tags: %s """ % (bookmark, description, tags) # Now, send it back with the new tag request = urllib2.Request(url_add + "?url=%s&tags=%s&description=%s" % \ (bookmark, urllib.quote_plus(tags.encode("UTF-8")), urllib.quote_plus(description.encode("UTF-8")))) add_ua(request) reply = urllib2.urlopen(request) xml = ElementTree.fromstring(reply.read()) if xml.attrib["code"] != "done": raise Exception("Update failed")

