Push and pull

When you update a blog, many systems have the ability to ‘ping’ another site to tell it that something has changed, typically using the weblogs.com XML-RPC interface.

I wanted to be able to receive these pings and to perform some simple operation as a result; in this case grabbing an file from the associated Movable Type blog. Here is a very simple Python CGI script which does just that, based on Jan-Klaas Kollhof’s neat little xmlrpc server module.

Update: This works with Movable Type – in your weblog config you can specify it as one of the sites to be notified by typing the CGI script’s URL into the ‘Others’ box. However, MT has a bug which gives it a tendency to misinterpret the results and think that the ping has failed when it has in fact succeeded. The call returns two values, and MT assumes that they will be in a specific order when the order is, in fact, irrelevant. To fix this, edit the lib/MT/XMLRPC.pm file and change:

  my($error, $msg) = $content =~

to say

    my($error) = $content =~  m!flerror.*?<boolean>(d+)</boolean>!s;
    my($msg) = $content =~  m!message.*?<value>(.+?)</value>!s;

at approx line 71.

Enjoyed this post? Why not sign up to receive Status-Q in your inbox?

© Copyright Quentin Stafford-Fraser