2005-08-21

The Advogato XMLRPC API

Since I still had a bunch of old Advogato entries I'd like to archive, post-process (to get rid of their weird HTML injection mishaps) and upload to my blogger account I drew up a quick pike script to mirror mine, or for that matter, any other Advogato blog. It was easy enough - good work on the API, guys! A kindly meant suggestion to you, by the way -- you may find that introducing a commenting system would lose you fewer writers to competing sites. In my case, that was what finally got me to switch over to Blogger. It's just not worth posting quality tech stuff, unless the reader base can easily talk back and thus further elevate the quality of a post.

Anyway, in case anyone else would want to mirror a log or a few as well, here it is:

#! /usr/bin/env pike

constant address = "http://www.advogato.org/XMLRPC";

int main( int argc, array(string) argv )
{
Protocols.XMLRPC.Client client = Protocols.XMLRPC.Client( address );
for( int i=1; i<argc; i++ )
mirror( argv[i], client );
}

int mirror( string user, Protocols.XMLRPC.Client client )
{
Calendar.TimeRange ctime, mtime;
int entries, i;
string html, filename;
[entries] = client["diary.len"]( user );
for( i=0; i<entries; i++ )
{
[[ctime, mtime]] = client["diary.getDates"]( user, i );
[html] = client["diary.get"]( user, i);
string filename = user + "." + i + ".txt";
Stdio.write_file( filename, html + "\n" + ctime->format_time() );
System.utime( filename, ctime->unix_time(), mtime->unix_time() );
}
return entries;
}
Categories:

5 comments:

  1. out of curiosity, why are you doing variable assignments in []?

    [entries] = ...
    [[ctime, mtime]] = ...
    [html] = ...

    [] are only used/needed for assignment to multiple variablkes at once:
    entries = ...
    [ctime, mtime] = ...
    html = ...

    greetings, eMBee.

    ReplyDelete
  2. Because the XMLRPC.Client class wrapped things up in levels of arrays everywhere and I preferred this syntax over indexing out lots of things. Less magic numeric constants and more focus on the code itself, where it's just positional parameters mapping towards corresponding positional parameters in Advogato's XMLRPC API anyway.

    I would have ended up with lots of temporary variables and cruft just to read out the data from returned results, had I done it otherwise.

    ReplyDelete
  3. oh, johan, this is your blog.
    i didn't recognize you by that half cut of face in the upper left corner :-)))
    (got to watch this more closely now :-)

    with regards to accessing things wrapped in arrays, this only works if you can be sure if the array never changes size.

    as for the number constants, you'd just append [0] to every expression, and not get any additional temporary variables.

    wether [a] = arr; is more readable than
    a = arr[0]; i am not sure. the latter is more fault tolerant.

    i don't know why XMLRPC.Client class wraps ecerything in arrays, but it maybe to allow the return of multiple values at some point, because if not, i can see no reason to return arrays in the first place. (unless they are playing games with referencing basic types)

    greetings, eMBee.

    ReplyDelete
  4. That's actually the beauty with the XMLRPC API:s; you do know the layout of what you get back, and don't need to fuss around like that. I'm not suggesting it's good for your everyday programming, but it improved the code in this piece IMO.

    And regarding XMLRPC.Client, I believe the design makes some sense, to make it wrap everything in an identical generic way; if I recall correctly, I did read through the code and the specs at the time since it didn't make sense to me, before having done that. (Then I immediately forgot all the details -- so I'm not going to pretend this description settles the design issue. :-)

    (I also don't see any good way of doing [[ctime, mtime]] = ... without using this assignment type, and still avoid using any temporary variables.)

    ReplyDelete
  5. I determined to transmigrate my antediluvian Advogato weblog to my WordPress installing tonight. I utilise Frontier - Client and XML RPC to have it off. It was surprisingly painless and simply took me about 25 transactions.

    ReplyDelete

Limited HTML (such as <b>, <i>, <a>) is supported. (All comments are moderated by me amd rel=nofollow gets added to links -- to deter and weed out monetized spam.)

I would prefer not to have to do this as much as you do. Comments straying too far off the post topic often lost due to attention dilution.

Note: Only a member of this blog may post a comment.