메뉴얼:Pywikibot/위키데이터

From mediawiki.org
This page is a translated version of the page Manual:Pywikibot/Wikidata and the translation is 43% complete.
Outdated translations are marked like this.

이 페이지는 기본 pywikibot 라이브러리를 사용하여 Wikidata에 파이썬 봇을 만드는 방법을 설명합니다.

파이썬 한 줄을 쓰지 않고 스크립트를 실행하고 싶다면 포함 된 Wikidata 스크립트를 참조하십시오.

경고! 경고: 방법과 결과는 Wikibase가 발전함에 따라 향후 변경 될 수 있습니다.
Pywikibot supports lexical data objects like Lexemes with release 7.2 and above.

설정

봇의 계정을 사용하여 기여 / 테스트를 시작하려면 user-config.py에 다음을 추가해야합니다.

창작 사이트
usernames['wikidata']['wikidata'] = 'YourBot'
테스트 사이트
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('wikipedia:en')  # any site will work, this is just an example
page = pywikibot.Page(site, 'Douglas Adams')
item = pywikibot.ItemPage.fromPage(page)  # 이것은 아무 페이지 오브젝트나 사용할 수 있게 할수 있습니다.
# you can also define an item like this
repo = site.data_repository()  # 이것은 DataSite 오브젝트입니다.
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.

# Edit an existing 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 make 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')


같이 보기

Some bot examples


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