radioAe6rt

Command line utility to affect WordPress blog postings

leave a comment »

Here is a quick Java hack to post file contents to a WordPress blog using the Apache XML-RPC 2.0 interface defined by MetaWeblog API.

The utility takes as input a file containing the content to be posted. The first line of the file must contain a comma separated list of categories under which the post should be classified. The second line of the file must contain the post title. Everything else in the file is assumed to be the post content, which is full HTML markup. Blank lines in the input are converted to <p>.

To compile

javac -classpath xmlrpc-2.0.jar Post.java

To run

java [-Dpost.preview={true|false}] -Dpost.url=https://secureBlogURL/xmlrpc.php -Dpost.username=someuser -Dpost.password=thepassword -classpath xmlrpc-2.0.jar:commons-codec-1.3.jar:. Post file

where the XML-RPC and Jakarta Commons Codec jars are available as Apache projects.

Moreover

  • The app uses a secure connection to your WordPress xmlrpc.php service if the URL starts with “https”. Otherwise an unsecure connection is used (i.e., username/password are passed in the clear).
  • someuser and thepassword are your WordPress admin username and password, respectively.
  • The MetaWebBlog publish flag is set to false, resulting in a post created with Draft status.
  • true can optionally be passed to -Dpost.preview to dump the output to stdout without actually posting to the network.
    Previewing is useful when tweaking the post, each time examining it for rendered acceptability in your local browser session.

Given a few liberties I took with some fun new language features, this is a Java 1.5 app. If you’re contrained to using Java 1.4, post a comment
and I’ll help you port it (hint: quick and dirty: comment out all the printlns and the msg methods, which use 1.5 language constructs
to iterate).

The app is super simple – no Java tricks, fully self-contained except for the two Apache jars you can readily download in binary form, and
about as simple XML-RPC as you can come by. Post a comment if you want to discuss it.

[tags]metaweblog api,wordpress[/tags]

Written by radioae6rt

March 28, 2006 at 11:06 am

Posted in Internet

Leave a Reply