"""tblib.py: A Trackback implementation in Python """ __author__ = "Matt Croydon " __copyright__ = "Copyright 2003, Matt Croydon" __license__ = "GPL" __version__ = "0.0.4" __history__ = """ 0.0.4: 1/22/03 - First public release, code cleanup 0.0.3: 1/22/03 - Removed hard coding that was used for testing 0.0.2: 1/21/03 - First working version. 0.0.1: 1/21/03 - Initial version. Thanks to Mark Pilgrim for helping me figure some module basics out. """ import httplib, urllib, urlparse """Everything I needed to know about trackback I learned from the trackback tech specs page http://www.movabletype.org/docs/mttrackback.html """ class TrackBack: def __init__(self, tbUrl, title, excerpt, url, blog_name): self.tbUrl = tbUrl self.title = title self.excerpt = excerpt self.url = url self.blog_name = blog_name def ping(self): # Create paramaters and make them play nice with HTTP # Python's httplib example helps a lot: # http://python.org/doc/current/lib/httplib-examples.html params = urllib.urlencode({'title': self.title, 'url': self.url, 'excerpt': self.excerpt, 'blog_name': self.blog_name}) headers = ({"Content-type": "application/x-www-form-urlencoded"}) # urlparse is my hero # http://www.python.org/doc/current/lib/module-urlparse.html tbUrlTuple = urlparse.urlparse(self.tbUrl) host = tbUrlTuple[1] path = tbUrlTuple[2] connection = httplib.HTTPConnection(host) connection.request("POST", path, params, headers) response = connection.getresponse() print response.status, response.reason data = response.read() print data connection.close()