Skip to content
forked from eldur/jwbf

Java Wiki Bot Framework is a library to maintain Wikis like Wikipedia based on MediaWiki.

License

Notifications You must be signed in to change notification settings

abhishek712/jwbf

 
 

Repository files navigation

JWBF - JavaWikiBotFramework.

Build Status Coverage Status Maven Central

The Java Wiki Bot Framework is a library to retrieve data from and maintain MediaWiki-based wikis such as Wikipedia. It has packages that handle basic tasks (login, cookies, encoding, token management) so that you can write your wiki bot without being a MediaWiki API expert. JWBF requires JRE 1.7.

Code sample

  /**
   * Sample bot that retrieves and edits an article.
   */
  public static void main(String[] args) {
    MediaWikiBot wikiBot = new MediaWikiBot("https://en.wikipedia.org/w/");
    Article article = wikiBot.getArticle("42");
    System.out.println(article.getText().substring(5, 42));
    // HITCHHIKER'S GUIDE TO THE GALAXY FANS
    applyChangesTo(article);
    wikiBot.login("user", "***");
    article.save();
  }

  static void applyChangesTo(Article article) {
    // edits the article...
  }

Table of contents

Code sample | Developer resources | Getting started | Dependencies | Working with Wikimedia | More resources

Developer resources

Getting started

JWBF uses Maven to automatically resolve dependencies. To use Maven to start a new project, follow the Maven in Five Minutes tutorial. For a more detailed introduction, see Maven's Getting Started guide.

The Java Wiki Bot Framework is available from two repositories. For a more stable version of JWBF, use the most recent version in the RELEASES repository at Maven Central. For the development version, which will be most up-to-date, use the most recent version in the SNAPSHOTS repository at oss.sonatype.org.

Dependencies

Once you have started your project in Maven and have a pom.xml file for your bot's project, add the appropriate JWBF dependency to the <dependencies> section. When you build your project, JWBF and its own dependencies will be downloaded automatically.

Beginning with jwbf 4.x.x Java 8 is required

From RELEASES:

<dependency>
  <groupId>net.sourceforge</groupId>
  <artifactId>jwbf</artifactId>
  <version>3.1.1</version>
</dependency>

If you want to use a different release of JWBF, find your desired version in RELEASES and change <version> to its listed title.

From SNAPSHOTS:

Add this to your <repositories> section:

<repository>
  <id>sonatype-nexus-snapshots</id>
  <name>Sonatype Nexus Snapshots</name>
  <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
  <snapshots>
    <enabled>true</enabled>
  </snapshots>
</repository>

Add this to your <dependencies> section:

<dependency>
  <groupId>net.sourceforge</groupId>
  <artifactId>jwbf</artifactId>
  <version>4.0.0-SNAPSHOT</version>
</dependency>

If you want to use a different snapshot of JWBF, find your desired version in SNAPSHOTS and change <version> to its listed title.

Examples

Here is one example of using JWBF to write a bot that can retrieve and edit an article on a desired wiki.

More Java examples (e.g. for queries) can be found at unit- and integration-test packages.

Working with Wikimedia

If you are working with Wikimedia sites, set an informative User-Agent header, because all Wikimedia sites require a HTTP User-Agent header for all requests.

//Creating a new MediaWikiBot with an informative user agent
HttpActionClient client = HttpActionClient.builder() //
  .withUrl("https://en.wikipedia.org/w/") //
  .withUserAgent("BotName", "1.0", "your Email or Maintainer UserName") //
  .withRequestsPerUnit(10, TimeUnit.MINUTES) //
  .build();
MediaWikiBot wikiBot = new MediaWikiBot(client);

See also

About

Java Wiki Bot Framework is a library to maintain Wikis like Wikipedia based on MediaWiki.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 99.8%
  • Shell 0.2%