Chheh:Pywikibot/Kiàn-li̍p lí ka-kī ê kiàn-pún

From mediawiki.org
Jump to navigation Jump to search
This page is a translated version of the page Manual:Pywikibot/Create your own script and the translation is 100% complete.

Chit ia̍h ū chi̍t-kóa siong-tong ki-pún ê pō͘-sò͘ hō͘ lí khai-sí siá lí ka-kī ê bot. Chhiáⁿ khak-jīn lí í-keng kiàn-li̍p lí ka-kī ê user-config.py tóng-àn!

Lí ē-sái tī chi̍t ê shell ia̍h-sī chi̍t ê kiàn-pún tiong sú-iōng ē-kha ê chí-lēng.

Beh khui shell, cháu python pwb.py shell;

Beh ēng kiàn-pún, chhiáⁿ kā tóng-àn myscript.py khǹg tī scripts/userscripts/ bo̍k-lio̍k tiong, chiah cháu python pwb.py myscript.

  • Beh ùi lí-ê Python kiàn-pún chhú-tit hóng-būn pywikibot hâm-sek-khò͘ ê khoân-hān, ēng:
import pywikibot
  • Beh chhú-tit chi̍t phiⁿ bûn-chiuⁿ, ēng ē-kha ê kiàn-pún, kî-tiong "pageName" sī lí beh chhú-tit ê bûn-chiuⁿ ê piau-tê (pí-lūn "Wikipedia:Bots" or "India"):
site = pywikibot.Site()
page = pywikibot.Page(site, u"pageName")
text = page.text

beh keng-sin chi̍t ê ia̍h-bīn, ēng:

page.text = u"newText"
page.save(u"Edit comment")
  • khòaⁿ chi̍t-kóa koan-hē kî-thaⁿ siūⁿ-hoat ê pywikibot tóng-àn -- scripts/basic.py tha̍k--khí-lâi siong-tùi khah kán-tan tio̍h-sǹg lí sī pywikibot ê sin-chhiú.
  • lí thang tī pywikibot/page.py tóng-àn chhōe tio̍h só͘-ū ē-ēng-tit ê Page hong-hoat.
  • basic.py kà lí beh án-chóaⁿ siat-tēng, he tī chē-chē bô-kāng ê bot lóng ēng-ē-tio̍h, lí chí su-iàu tēng-gī beh siá tī bûn-chiuⁿ bûn-pún lāi ê jī-chhoàn.
  • Beh thia̍p-tāi hóng-būn chi̍t cho͘ bûn-chiuⁿ, tī pywikibot/pagegenerators.py (chham-oa̍t kū bûn-kiāⁿ) chhōe chi̍t-kóa ē hôe-thoân chi̍t cho͘ bûn-chiuⁿ ê mi̍h-kiāⁿ. Pí-lūn CategoryPageGenerator ē-tàng tī Lūi-pia̍t:Chāi-sè jîn-bu̍t lūi-pia̍t tiong chò chi̍t-kóa tōng-chok:
import pywikibot
from pywikibot import pagegenerators
site = pywikibot.Site()
cat = pywikibot.Category(site,'Category:Living people')
gen = pagegenerators.CategorizedPageGenerator(cat)
for page in gen:
    #Do something with the page object, for example:
    text = page.text

Chham-oa̍t


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