Manual:Pywikibot/Wikidata

This page is talking about to run python bots on Wikidata with using trunk pywikibot library.

Configurating
you must add this to your user-config.py: in order to use the wikidata-test-repo instead of the productive one add:

Creating a DataPage object
Different ways creating a DataPage an Page object for wikidata: REMEMBER: You can not change any item, value or label without getting data first

Getting data
Get the data in a simple way

Changing or creating claims/statements

 * property can be a string like "capital" or "p36" or "P36" or "36" or 36
 * value can be a string like "Moscow" or "Q649" or "q649" or "649" or 649
 * refs is optional and if you doesn't add any references the bot will change either:
 * ref1 can be a string like "imported from" or "p143" or etc
 * value1 can be a string like "English Wikipedia" or "q328" or etc
 * other refs are optional too

and if you run your bot on English values, the bot won't work
 * Remember:Important:language of values must the same as the Wikipedia page you load at first e.g. If you load Russia from Deutsch Wikipedia your values must be:

If there was a claim already the code changes the claim, and there was not the code adds the claim.

Removing claim or claims
you can add the property in the way told above, value is optional and it's better to use when we have multiple claim for an statement if you don't use value, every claim that use the property will be removed

Working with rewrite branch
Write access is enabled, just hasn't been documented yet.

CAUTION: The methods and results may be changed in future

Example
Simple example for creating new items.

Caution: Use this code snippet with care. It does not test whether a data repository item already exists. It only test whether it exists for a given site page. This could also mean that a given site page as no language link on a given repository page. This must be checked before a page is created.