quickstatements-to-wikibase-edit

Convert QuickStatements commands into wikibase-edit format

Usage no npm install needed!

<script type="module">
  import quickstatementsToWikibaseEdit from 'https://cdn.skypack.dev/quickstatements-to-wikibase-edit';
</script>

README

quickstatements-to-wikibase-edit

Tools to convert QuickStatements commands into wikibase-edit format.

:warning: Status: experimental

Supported features

  • add statements with qualifiers and references
  • add labels, descriptions, aliases, sitelinks
  • create items
  • merge items

Missing features

  • remove statement
  • no check is performed to see if a statement already exists, creating duplicated statement if it does

CLI

Install

# Should make the commands `wb` and `quickstatements-to-wikibase-edit` available from anywhere
npm install --global wikibase-cli quickstatements-to-wikibase-edit
# Make sure your credentials are setup for the target instance (example below with wikidata.org)
wb config credentials https://www.wikidata.org test

Usage

# Should generate edits, creations, and merges NDJSON files, depending on the commands content
quickstatements-to-wikibase-edit ./quickstatement_commands.txt

cat 0ba886b6-edits.ndjson | wb edit-entity --batch --summary 'fixing stuff'
cat 0ba886b6-creations.ndjson | wb create-entity --batch --summary 'fixing stuff'
cat 0ba886b6-merges.ndjson | wb merge-entity --batch --summary 'fixing stuff'

JS

Install

npm install wikibase-edit quickstatements-to-wikibase-edit

Usage

const wbEdit = require('wikibase-edit')({ instance, credentials })
const quickstatementsToWikibaseEdit = require('quickstatements-to-wikibase-edit')

const commands = `
Q4115189	P31	Q1
Q4115189	P373	"Antoni Ignacy Mietelski"
Q1214098	P1476	pl:"Krzyżacy"
CREATE
LAST	Sfrwiki	"Le croissant magnifique!"
LAST	Lfr	"Le croissant magnifique!"
Q340122	Aen	"Cyprjan Kamil Norwid"
MERGE	Q1	Q2
Q340122	Aen	"Cyprian Kamil Norwid|Cypryan Kamil Norvid"
`

const { edits, creations, merges } = quickstatementsToWikibaseEdit(commands)

for (const edit of edits) {
  await wbEdit.entity.edit(edit)
}

for (const creation of creations) {
  await wbEdit.entity.create(creation)
}

for (const merge of merges) {
  await wbEdit.entity.merge(merge)
}