Posts Tagged ‘api’

MediaWiki bot using JWBF (Java)

wiki! wiki!

wiki! wiki!

One of the nice things about Java is there seems to be a friendly (or at least relatively friendly) API for everything.

Java Wiki Bot Framework (JWBF) is a Java framework for working with wikis running MediaWiki (the wiki software used by Wikipedia and all the other Wikimedia Foundation projects).

A little off subject: who thought it was a good idea to name two distinct but related things WikiMedia and MediaWiki? Good luck keeping those terms straight.

Back to JWBF: It is pleasantly easy to use. Admittedly, my needs are far from complex: replace the text of a couple of templates on a regular basis. It’s hardly glamorous programming, but it should save us some time at work. Now we’ll have more time to sing along with
Dr. Horrible’s Sing-Along Blog.
Invent a freeze ray.

Happily the library exists in the central maven repository, so getting it included in my project is easy enough:

    <dependency>
      <groupId>net.sourceforge</groupId>
      <artifactId>jwbf</artifactId>
      <version>1.2-186</version>
      <scope>compile</scope>
    </dependency>

Actually using the framework is as easy as this:

        MediaWikiBot mediaWikiBot =
            new MediaWikiBot( "http://hostname/wiki/" );
        mediaWikiBot.login( "CurrentlyDeployedBot", "password" );
        Article article = new Article(mediaWikiBot.readContent(
            "Template:Currently deployed/Arinc" ), mediaWikiBot );
        article.setText( "Test" );
        article.save();

It’s always nice when things are this easy. *cheers*

One more thing: if you’re looking to create a bot or script for automatic or semi-automatic usage of Wikipedia, please review Wikipedia’s bot policy first.

 

potbs4j 0.4: Java library for Pirates of the Burning Sea web services

Pirates in your Java, sacking the classloader.

Pirates in your Java, sacking the classloader.

A few weeks ago I put together a Twitter publisher for Pirates of the Burning Sea (PotBS) for my wife.  She plays the game perhaps a bit too religiously. :-)   Anyhow, two things get published to twitter: (1) server status changes, and (2) in-game port status changes (who is battling who).

To make life a little easier, I wrote potbs4j, a Java library  to work with PotBS services. (My name for the library is genius, really!)  There really wasn’t any need to couple the twitter publisher with XML parsing and HttpURLConnection.

I doubt ayone will make use of the library, but if anyone is really interested in using it, I’ve worked out some usage instructions here.

If you’re using Maven (highly recommended), just include the potbs4j in your list of dependencies:

<dependency>
<groupId>com.ashlux.potbs</groupId>
<artifactId>potbs4j</artifactId>
<version>0.4</version>
</dependency>

Since potbs4j does not exist in the central repository, you will also need to add my maven repository (it’s slow but works) to your pom.xml:

<repositories>
<repository>
<id>ashlux-repository</id>
<url>http://www.ashlux.com/maven2/repo</url>
<releases>
<enabled>true</enabled>
</releases>
</repository>
<repository><id>ashlux-snapshot-repository</id>
<url>http://www.ashlux.com/maven2/snapshotRepo</url>
<snapshots>
<enabled>true</enabled>
</snapshots></repository>
</repositories>

You can get the server status with the following code:

ServerStatusService serverStatusService =
new ServerStatusServiceImpl("apikey", "userid");

// get list of all server statuses
ServerListDocument serverListDocument =
serverStatusService.getAllServerStatuses();

// get server status for a single server
ServerDocument serverDocument =
serverStatusService.getServerStatus(ServerName.Antigua);

You can get the server status with the following code:

LandmarkStatusService landmarkStatusService =
new LandmarkStatusServiceImpl("apikey", "userid");
// get list of all port statuses for a server

PortListDocument portListDocument =
landmarkStatusService.getAllLandmarkStatuses(ServerName.Antigua);

// get list of all port statuses for a server
PortListDocument portListDocument =
landmarkStatusService.getLandmarkStatus(ServerName.Antigua, PortName.IRSH_PT);

There are also two utility classes NationUtils (for converting a nation to a nationality) and PortUtils (for converting a PortName.Enum to a string).

An important thing to keep in mind: the library currently does NOT cache results, so you will need to handle this on your own.  Both of the services do implement a method called getMinimumUpdateFrequency that returns the minimum number of minutes you should wait until calling the service.

The source code is hosted on github in all its glory.