Iōng-chiá:A-lú-mih/bot-kahak

Wikipedia (chū-iû ê pek-kho-choân-su) beh kā lí kóng...

(This tutorial contains some bad English, if you know any better way to say about any concept, feel free to tell me.)

setting up pywikibot[siu-kái | kái goân-sí-bé]

1. Install python on your computer if you haven't. (Here is some windows version, if you are using MacOS than it already have a python on it.)

2. Download pywikibot script. (Download and extract "core.tar.gz" to the location you prefered.) There are some dependencies for a full supported pywikibot but I think the scripts below don't need those dependencies.

3. Set up the configuration file core/user_config.py by typing "python pwb.py" in the command line (while browsing at the "core" folder), or just edit (or create) the file with the code below:

family = 'wikipedia' # your default family (wikipedia, commons, wiktionary...)
mylang = 'zh-min-nan' # your default site
usernames['wikipedia']['zh-min-nan'] = u'yourbotaccountname' # zh-min-nan account
usernames['wikidata']['wikidata'] = u'yourbotaccountname' # wikidata account

console_encoding = 'utf-8'

pywikibot for interwiki (sitelink)[siu-kái | kái goân-sí-bé]

4. Write your own sitelink bot and save it into core/scripts/<file_name_as_you_like.py>. Here I have a simple example:

import pywikibot

# Using English wikipedia to find the wikidata item.
site = pywikibot.Site('en', 'wikipedia') 

# The page on English wikipedia that you want to add a zh-min-nan sitelink.
page = pywikibot.Page(site, 'yourtargetarticle') 

# Access the item on wikidata via English wikipedia (by the above information)
item = pywikibot.ItemPage.fromPage(page)
item.get()

# Add a zh-min-nan sitelink on wikidata.
item.setSitelink(sitelink={'site': 'zh_min_nanwiki', 'title': 'yourtargetarticle'}, summary=u'Set sitelink')

5. Execute your sitelink bot by typing "python pwb.py file_name_as_you_like" in the command line.

mutiple article looping[siu-kái | kái goân-sí-bé]

(Haven't tried yet)

# -*- coding: utf-8  -*-
import pywikibot

# Use a English wikipedia to find the wikidata item.
site = pywikibot.Site('en', 'wikipedia') 

# Make a list (array) of articles (on en wikipedia) that you want sitelinks to be added. 
article_list_en = ['enarticletitle00', 'enarticletitle01', 'enarticletitle02']

# The counterpart list for zh-min-nan wikipedia.
article_list_nan = ['nanarticletitle00', 'nanarticletitle01', 'nanarticletitle02']

# (Here above are just manually set lists that with only 3 items. You may use some scripts to generate larger lists automatically.)

# The for loop according the lists above.
for i in range(len(article_list_en)):
    # The page on English wikipedia that you want to add a zh-min-nan sitelink.
    page = pywikibot.Page(site, article_list_en[i]) 
    
    # Access the item on wikidata via English wikipedia (by the above information)
    item = pywikibot.ItemPage.fromPage(page)
    item.get()

    # Add a zh-min-nan sitelink on wikidata.
    item.setSitelink(sitelink={'site': 'zh_min_nanwiki', 'title': article_list_nan[i]}, summary=u'Set sitelink')
    

"""
#or use dictionary:

article_dictionary = {
   'enarticletitle00': 'nanarticletitle00',
   'enarticletitle01': 'nanarticletitle01',
   'enarticletitle02': 'nanarticletitle02'
}

for key in article_dictionary:
    # The page on English wikipedia that you want to add a zh-min-nan sitelink.
    page = pywikibot.Page(site, key) 
    
    # Access the item on wikidata via English wikipedia (by the above information)
    item = pywikibot.ItemPage.fromPage(page)
    item.get()

    # Add a zh-min-nan sitelink on wikidata.
    item.setSitelink(sitelink={'site': 'zh_min_nanwiki', 'title': article_dictionary[key]}, summary=u'Set sitelink')
    
"""