Chheh:Pywikibot/Wikidata

From mediawiki.org
Jump to navigation Jump to search
This page is a translated version of the page Manual:Pywikibot/Wikidata and the translation is 58% complete.
Other languages:
Bân-lâm-gú • ‎Deutsch • ‎English • ‎Nederlands • ‎Tagalog • ‎español • ‎français • ‎italiano • ‎polski • ‎português do Brasil • ‎Ελληνικά • ‎български • ‎русский • ‎українська • ‎العربية • ‎中文 • ‎日本語 • ‎한국어

Chit ia̍h kái-soeh án-chóaⁿ ēng ki-pún pywikibot hâm-sek-khò͘ tī Wikidata téng kiàn-li̍p bot.

Nā-sī lí chí-sī siūⁿ beh cháu chi̍t-kóa kiàn-pún, bô beh siá python, khòaⁿ the included Wikidata scripts.

Caution! Caution: The methods and results may be changed in the future, as Wikibase evolves.
pywikibot currently does not support lexical data objects like Lexemes. Use WikibaseIntegrator or LexData to edit those instead.

Phòe-tì

Beh khai-sí ēng lí-ê bot kháu-chō kòng-hiàn/chhì-giām, lí it-tēng ài tī lí-ê user-config.py lāi ka-thiam ē-kha chit chōa:

Chèng-sek bāng-chām
usernames['wikidata']['wikidata'] = 'YourBot'
Chhì-giām bāng-chām
usernames['wikidata']['test'] = 'YourBot'

see Wikidata:Creating a bot for an extended documentation. pywikibot core supports most Wikibase features already, e.g., qualifiers, sources, properties with item, coordinate, time, and string type.

import pwb  # only needed if you haven't installed the framework as side-package
import pywikibot
site = pywikibot.Site('en', 'wikipedia')  # jīm-hô bāng-ia̍h lóng ē ūn-chok, che chí-sī chi̍t ê lē
page = pywikibot.Page(site, 'Douglas Adams')
item = pywikibot.ItemPage.fromPage(page)  # che ē-sái tī jīm-hô ia̍h-bīn mi̍h-kiāⁿ sú-iōng
# lí mā ē-sái án-ne tēng-gī chi̍t ê item
repo = site.data_repository()  # this is a DataSite object
item = pywikibot.ItemPage(repo, 'Q42')  # This will be functionally the same as the other item we defined
item.get()  # you need to call it to access any data.
sitelinks = item.sitelinks
aliases = item.aliases
if 'en' in item.labels:
    print('The label in English is: ' + item.labels['en'])
if item.claims:
    if 'P31' in item.claims: # instance of
        print(item.claims['P31'][0].getTarget())
        print(item.claims['P31'][0].sources[0])  # let's just assume it has sources.

# Pian-chi̍p í-keng tī-leh ê item
item.editLabels(labels={'en': 'Douglas Adams'}, summary='Edit label')
item.editDescriptions(descriptions={'en': 'English writer'}, summary='Edit description')
item.editAliases(aliases={'en':['Douglas Noel Adams', 'another alias']})
item.setSitelink(sitelink={'site': 'enwiki', 'title': 'Douglas Adams'}, summary='Set sitelink')
item.removeSitelink(site='enwiki', summary='Remove sitelink')

# You can also made this all in one time:
data = {'labels': {'en': 'Douglas Adams'},
  'descriptions': {'en': 'English writer'},
       'aliases': {'en': ['Douglas Noel Adams', 'another alias'], 'de': ['Douglas Noel Adams']},
     'sitelinks': [{'site': 'enwiki', 'title': 'Douglas Adams'}]}
item.editEntity(data, summary='Edit item')

Chham-oa̍t

Chi̍t-kóa bot kiàn-pún


If you need more help on setting up your Pywikibot visit the #pywikibot IRC channel connect or pywikibot@ mailing list.