WordPress publisher bot

Inspired by offlineblog’s blog about Live blogging and the WordPress plugins like described on my blog, and at offlineblog and the bloggy robot which can publish to blogger.com. I thought this could also be possible to perform the same with a WordPress robot.

The solution simply works by adding the robot wp-bot@appspot.com to a Wave. Then it publishes your wave to the site as an embedded wave to WordPress. With this you get a permalink to the blog, where the content is hosted. I was unable to using the API’s that Google is using for displaying that the content is shared. If you know how to use please let me know.

I found the wordpress-java library to help with creating the XMLRPC code, which I was unable to use. With this library it is pretty simple to create a blog with some content. And since the content I’m posting just is wave id=’waveID’ bgcolor=’#ffffff’, it is pretty easy to craft.

The robot in action works the following way.


The code looks like the following.

public class WPRobotServlet extends AbstractRobotServlet {
      private String ownname = "wp-bot@appspot.com";
    public void processEvents(RobotMessageBundle bundle) {
        Wavelet wavelet = bundle.getWavelet();
        // when the Robot is added publish to the robot
        if (bundle.wasSelfAdded()) {

            Blip blip = wavelet.appendBlip();
            TextView textView = blip.getDocument();
            textView.append(ownname+ " added version " +this.getVersion() +" \n");
            textView.appendMarkup("\n <a href=\"http://masteringwave.com/\">MasteringWave</a> <br />");
            String rootText = wavelet.getRootBlip().getDocument().getText();
            // find the first line, which will be the title to the blog
            String firstLine ;
                firstLine =     rootText.substring(0,rootText.indexOf("\n"));
                firstLine = rootText;
            textView.append( uploadWave(firstLine, wavelet.getWaveId()));

    private String uploadWave(String title, String waveID){
           String sXmlRpcURL = "http://wp-bot.masteringwave.com/xmlrpc.php";
              String sUsername = "wave";
              String sPassword = "<SECRET>";
              // Hard-coded blog_ID
              String blog_ID = "1";

              // XML-RPC method
              String sXmlRpcMethod = "metaWeblog.newPost";
              // the content of the blog
              String sContent = "[wave id=\""+waveID+"\" bgcolor=\"#ffffff\"]";

                  // Try block to create the upload
                Wordpress wp = new Wordpress(sUsername, sPassword, sXmlRpcURL);
                  Page newPost = new Page();
                  String resultId = wp.newPost(newPost, "draft");
                  return wp.getPost(Integer.parseInt(resultId)).getPermaLink();
              catch( Exception e )
               return e.toString();


The full code can be found at http://code.google.com/p/masteringwave/source/browse/#svn/trunk/WP-BOT.

If you just want to check it out, just add the robot wp-bot@appspot.com to your Wave and the wave will be published.

Bookmark and Share