wikiq

0.0.8 • Public • Published

WikiQ

WikiQ allows you to query wikipedia pages and other info using WikiMedia API. WikiMedia is pretty well documented, this provides a NodeJS adapter to query different information from Wikipedia as:

See APIs details here

Install using npm:

npm install ---save wikiq

Parse Pages

To parse and get content of page Zika_virus:

var wiki = require("wikiq")();
 
wiki.page("Zika_virus").parse(function(err, resp) {
 
    console.log("got page resp, err: %s", err);
    console.log(resp);
});

To get custom properties:

var wiki = require("wikiq")();
 
wiki.page("Zika_virus").prop(["sections", "templates"])
    .parse(function(err, resp) {
 
    console.log("got page resp, err: %s", err);
    console.log(resp);
});

See more detail about properties here

Query Pages

To query page Zika_virus:

var wiki = require("wikiq")();
 
wiki.page("Zika_virus").query(function(err, resp) {
 
    console.log("got page resp, err: %s", err);
    console.log(resp);
});

Similary can specify custom properties, as in parse using prop method

See more detail about properties here

Get Category Tree

Category tree provides the category tree for a page title, you can query the same using:

var wiki = require("wikiq")();
 
wiki.category("Malaria").tree(function(err, resp) {
 
    console.log("got category resp, err: %s", err);
    console.log(resp);
});

See more detail about properties here

Query Template Info

Wikipedia has lot of templates, or you can create a new template - which are used across lot of pages in Wikipedia. To query a template info:

var wiki = require("wikiq")();
 
wiki.template("About").data(function(err, resp) {
 
    console.log("got template info resp, err: %s", err);
    console.log(resp);
});

See more detail about properties here

API

Wikiq API is simple, once you have required wikiq, you simply select the type of api:

Every type has these common methods:

  • format (string): format of the response. Wikipedia suppports
    • json
    • none
    • php
    • xml
  • prop (string or array): specify list of properties to fetch, varies as per the API type

Also the method follows fluent interface, so you can kepp on piping API calls.

wiki.api()
      .format('json')
      .action('query')
      ...

Page API

Page API has following methods:

  • query (callback): query a page, using action:query
  • parse (callback): parse a page, using action:parse
  • templates (callback): gets the templates in a page
  • sections (callback): gets the sections in a page
  • xml (callback): gets the complete xml parsetree of page
  • images (callback): gets the images of page

Category API

Category API has following methods:

  • tree (callback): gets the category tree

Template API

Template API has following methods:

  • data (callback): gets the template data

Custom API

You can hit your own custom API or action as they are in Wikimedia:

wiki.api()
      .format('json')
      .action('query')
      .title('Malaria')
      .props('images')
      .hit(done)

Readme

Keywords

Package Sidebar

Install

npm i wikiq

Weekly Downloads

1

Version

0.0.8

License

MIT

Last publish

Collaborators

  • ashishjain