Wikidata:Tools/WikibaseJS-cli

From Wikidata
Jump to navigation Jump to search
Wikidata cli search screenshot zoom

wikibase-cli, also known as WikibaseJS-cli, or wikibase-cli (Q87194660), is a command-line interface to Wikidata or any other Wikibase (Q16354758) instance, based on wikibase-edit. It can be used from the terminal as an alternative interface to the web browser interface, or in scripts to run many edits.

As stated in the name, WikibaseJS-cli is written in JavaScript (Q2005), to be run as a Node.js (Q756100) process. This process can thus be run in any environment where Node.js (Q756100) can be installed, or alternatively within a Docker container, see installation documentation.

Documentation

[edit]

See Documentation

Samples

[edit]

The documentation at https://github.com/maxlath/wikibase-cli includes many samples. There are also some more code samples at

A few additional ones here.

Labels and descriptions

[edit]
add a label
wd set-label Q89208827 en "Aellopus Saxum"
add a description
wd set-description Q89208827 en "saxum on asteroid 101955 Bennu"

Adding statements

[edit]
add a statement (simple)
wd ac Q75887503 P735 Q18009833
add a statement (simple, with edit summary)
wd ac Q96817942 P921 Q11558 --summary 'adding claim [[Property:P921]]: [[Q11558]]'
add a statement (simple, using a template)

step #1: create a file "givenname.js" with the following:

module.exports = (qid, gn) => {
  return {
    id: qid,
    claims: { P735: { value: gn } },
    summary: "adding claim [[Property:P735]]: [[" + gn + "]]" 
  }
}

step #2: test it with (no edit is done):

wd ee givenname.js Q75887503 Q18009833 --dry

step #3: run it with (edits Wikidata):

wd ee givenname.js Q75887503 Q18009833
add a statement (complex with special somevalue, qualifier and reference, using a template)

step #1: create a file "templatehay.js" with the following:

module.exports = (qid, hay, color) => {
  return {
    id: qid,
    claims: {
      P2827: {
       "snaktype":"somevalue",
      //  value: "Q53569537",
	qualifiers: { P1932: color  },
        references: [ { P248: 'Q96634446', P8662: hay } ]
      }
    } ,
    summary: "adding claim [[Property:P2827]]: " + color + " from [[Q96634446|L'Haÿ]]" 
  }
}

step #2: test it with (no edit is done):

wd ee templatehay.js Q60964601 1837 "rose vif" --dry

step #3: run it with (edits Wikidata):

wd ee templatehay.js Q60964601 1837 "rose vif"

Create items

[edit]
create items similar to another item

step #1: create a template file based on suitable sample (here Q100700188)

wd generate-template --create-mode Q100700188 > Qianguimon.js

step #2: open file

step #3: edit it into a template

module.exports = function () {
  return {
    type: 'item',
    labels: {
      en: 'Qianguimon elongatum',
      nl: 'Qianguimon elongatum'
    },
    descriptions: {
      en: 'species of crustacean',
      nl: 'taxon'
    },
    aliases: {},
    claims: {
      // instance of: taxon
      P31: 'Q16521',
      // taxon name
      P225: 'Qianguimon elongatum',
      // taxon rank: species
      P105: 'Q7432',
      // parent taxon: Qianguimon
      P171: 'Q100605554',
      // WoRMS-ID for taxa
      P850: '1062897'
    },
    sitelinks: {}
  }
}
module.exports = function (name, identifier) {
  return {
    type: 'item',
    labels: {
      en: name,
      nl: name
    },
    descriptions: {
      en: 'species of crustacean',
      nl: 'taxon'
    },
    aliases: {},
    claims: {
      // instance of: taxon
      P31: 'Q16521',
      // taxon name
      P225: name,
      // taxon rank: species
      P105: 'Q7432',
      // parent taxon: Qianguimon
      P171: 'Q100605554',
      // WoRMS-ID for taxa
      P850: identifier
    },
    sitelinks: {}
  }
}

step #4: create similar ones using that template:

wd ce Qianguimon.js "Qianguimon rongxianense" 1389612

step #5: check result

This could have been: Q100700189
create an item based on a premade template

step #1: copy latinscriptfemalegivenname.js to your cli directory

step #2: use it

wd ce latinscriptfemalegivenname.js "Clarenza"

step #3: check the result

This could have been: Q100967811

Code

[edit]

Issues

[edit]

To signal a bug or ask for help, you can open an issue at https://github.com/maxlath/wikibase-cli/issues.

List of edits

[edit]

Edits done by wikibase-edit use the WikibaseJS-cli tag by default, which allows to get a list of edits done this way: WikibaseJS-cli in Recent Changes.

When using the batch mode, edits are grouped in EditGroups.

Userbox

[edit]
Babel user information
Wikibase CLI screenshotThis user reads and edits Wikidata from the command line using wikibase-cli.
Users by language

You can share your love for this tool by displaying a userbox on your user page: add {{#babel:Wikibase CLI}}

List of users: Category:Wikibase CLI user